I am creating a graph structure for training purposes. I use the TDD approach, so I write a lot of unit tests. However, I am still figuring out how to prove the correctness of my unit tests.
For example, I have this class (not including the implementation, and I simplified it)
public class SimpleGraph(){
public boolean addEdge(Vertex v1, Vertex v2) { ... }
public boolean addVertex(Vertex v1) { ... }
}
I also created these unit tests.
@Test
public void SimpleGraph_addVertex_noSelfLoopsAllowed(){
SimpleGraph g = new SimpleGraph();
Vertex v1 = new Vertex('Vertex 1');
actual = g.addVertex(v1);
boolean expected = false;
boolean actual = g.addEdge(v1,v1);
Assert.assertEquals(expected,actual);
}
Ok, this is awesome. There is only one question here, I proved that functions only work for this case. However, in my courses on graph theory, everything I do theoretically proves theorems (induction, contradiction, etc.).
So, I was wondering if there is a way to prove my unit tests mathematically for correctness? So there is good practice for this. Therefore, we test the block for correctness, instead of testing it for a specific result.