summaryrefslogtreecommitdiff
path: root/src/03/matrix_test.c
blob: 93970705d1cf55a4fb39a8f7368bda20321461e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "matrix.h"
#include <cgreen/cgreen.h>
#include <string.h>

Ensure(every_edge_is_traversed_in_both_directions_at_least_once) {
  int n = 16;
  int visited[16] = {0};
  int graph[16][16] = {
    {0,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0},
    {1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0},
    {0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0},
    {1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0},
    {1,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0},
    {0,0,0,1,0,0,0,1,0,1,1,0,0,0,0,0},
    {0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0},
    {0,0,0,0,1,0,0,0,0,1,0,0,1,1,0,0},
    {0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
    {0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,1,0,0,0,0,0,1,0},
    {0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1},
    {0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0},
  };

  matrix_traverse(n, graph, visited, 0);
  printf("\n");

  for (int i = 0; i < n; ++i)
    for (int j = 0; j < n; ++j)
      assert_that(graph[i][j], is_equal_to(0));
}

TestSuite *matrix_tests() {
  TestSuite *x = create_test_suite();

  add_test(x, every_edge_is_traversed_in_both_directions_at_least_once);

  return x;
}