This can be generalized to give two tests of primality. Consider the equation $$\frac{pa + b}{pb +c} = \frac{a}{c}$$ where $p$, $a$, $b$, and $c$ are all positive integers with $a, b, c < p$. This is a base $p$ version of the question. Suppose that $p$ is some fixed positive integer. We will say that $(a, b, c)$ is a solution if the equation is satisfied. We will say that a solution is trivial if $a = b = c$; otherwise we will say the solution is nontrivial. There are $p -1$ trivial solutions. Check that if $(a, b, c)$ is a solution with any two of $a$, $b$, and $c$ equal then the solution is trivial.
Suppose that $(a, b, c)$ is a nontrivial solution. In this case the greatest common divisor of $b$ and $p - 1$ is greater than $1$. Also the greatest common divisor of $c$ and $p$ is greater than $1$. We can prove two theorems:
Theorem 1 Suppose that $p > 1$ is an integer. Then $p$ is prime if and only if there are no nontrivial solutions.
In one direction this follows from the observation that the greatest common divisor of $c$ and $p$ is greater than $1$. Recall that $c < p$. In the other direction if $p = mn$ then ($n - 1, p - 1, m(n - 1) )$ is a nontrivial solution.
Theorem 2 Suppose that $p > 2$ is an even integer. Then $p - 1$ is prime if and only if and only if in every nontrivial solution $(a, b, c)$ we have $b = p - 1$.
In one direction this follows from the observation that the greatest common divisor of $b$ and $p - 1$ is greater than $1$. In the other direction if $p - 1 = mn$ then $(\frac{1}{2} (m + 1), \frac{1}{2} (m + 1)n, \frac{1}{2} mn)$ is a nontrivial solution.
One can also prove that if $(a, b, c)$ is a nontrivial solution then $2a \leq c < b$. If $p = 4$ the solution $(1, 3, 2)$ shows these limits are the best possible.
One can also prove that the number of notrivial solutions is even unless $p$ is the square of an even integer.