-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuzztesting.c
More file actions
88 lines (54 loc) · 1.55 KB
/
fuzztesting.c
File metadata and controls
88 lines (54 loc) · 1.55 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* fuzzsudoku - generate a series of random sudokus for testing sudoku create and build
*
* usage:
* fuzzquery numSudokus
*
*
* u
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
#include "./library/memory.h"
#include "./puzzle/puzzle.h"
#include "./create/create.h"
#include "./solve/solve.h"
int
main(const int argc, char *argv[])
{
clock_t start, end;
double cpu_time_used;
double total = 0;
//Change the depth string to an integer
char* difficulty = count_calloc_assert(strlen(argv[1]), sizeof(char) + 1, "difficulty");
int numSudokus;
strcpy(difficulty, argv[1]);
sscanf(argv[2], "%d", &numSudokus);
time_t t;
srand((unsigned) time(&t));
for(int i = 1; i <= numSudokus; i ++){
sleep(1);
//Create a full sudoku
puzzle_t* puzzle = puzzle_new(9);
build_full_sudoku(puzzle, difficulty);
//Create an incomplete sudoku
create_sudoku(puzzle, difficulty);
int num_solutions = count_num_solutions(puzzle, difficulty);
//Solve (and track time)
start = clock();
//solve method
solve_sudoku(puzzle,0,0,difficulty);
end = clock();
cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
total += cpu_time_used;
printf("Run %d- valid: %s, solve time: %f seconds, # of solutions: %d\n", i, (is_valid_solved(puzzle)) ? "true" : "false", cpu_time_used, num_solutions);
puzzle_delete(puzzle);
}
printf("\nAverage run time %f: seconds\n", total/numSudokus);
free(difficulty);
}