Added test cases

Signed-off-by: gothictomato <gothictomato@pm.me>
This commit is contained in:
gothictomato
2022-07-17 21:40:34 -04:00
parent c7a2f3f95a
commit 7ce1e80739
5 changed files with 114 additions and 156 deletions

87
tests/masterTest.c Normal file
View File

@@ -0,0 +1,87 @@
#include "masterTest.h"
#include <stdio.h>
#include "../cnf.h"
#include "../gpusolver.h"
#include "../time.h"
i32 runTests() {
i32 res = runuf20();
if (res != 0) return res;
res = runuf50();
if (res != 0) return res;
res = runuuf50();
return res;
}
i32 runuf20() {
printf("Running against uf20\n");
u32 passed = 0;
u64 tottime = 0;
for (u32 i = 0; i < 1000; ++i) {
char buf[128];
i32 len = sprintf(buf, "/home/lev/Downloads/uf20/uf20-0%u.cnf", i + 1);
cnf* c = readDIMACS(buf);
sortlastnum(c, c->litcnt);
u64 start = utime();
i32 res = gpusolve(c);
u64 stop = utime();
tottime += (stop - start);
freecnf(c);
if (res == 0) passed++;
}
printf("Passed %u / 1000 tests\n", passed);
printf("Took %lf s total, %lf s on avg\n", ((f64) tottime) / 1000000.0, ((f64) tottime) / 1000000000.0);
}
i32 runuf50() {
printf("Running against uf50\n");
u32 passed = 0;
u64 tottime = 0;
for (u32 i = 0; i < 1000; ++i) {
char buf[128];
i32 len = sprintf(buf, "/home/lev/Downloads/uf50/uf50-0%u.cnf", i + 1);
cnf* c = readDIMACS(buf);
sortlastnum(c, c->litcnt);
u64 start = utime();
i32 res = gpusolve(c);
u64 stop = utime();
tottime += (stop - start);
freecnf(c);
if (res == 0) passed++;
}
printf("Passed %u / 1000 tests\n", passed);
printf("Took %lf s total, %lf s on avg\n", ((f64) tottime) / 1000000.0, ((f64) tottime) / 1000000000.0);
}
i32 runuuf50() {
printf("Running against uuf50\n");
u32 passed = 0;
u64 tottime = 0;
for (u32 i = 0; i < 1000; ++i) {
char buf[128];
i32 len = sprintf(buf, "/home/lev/Downloads/uuf50/uuf50-0%u.cnf", i + 1);
cnf* c = readDIMACS(buf);
sortlastnum(c, c->litcnt);
u64 start = utime();
i32 res = gpusolve(c);
u64 stop = utime();
tottime += (stop - start);
freecnf(c);
if (res == 0) passed++;
}
printf("Passed %u / 1000 tests\n", passed);
printf("Took %lf s total, %lf s on avg\n", ((f64) tottime) / 1000000.0, ((f64) tottime) / 1000000000.0);
}

8
tests/masterTest.h Normal file
View File

@@ -0,0 +1,8 @@
#pragma once
#include "../types.h"
i32 runTests();
i32 runuf20();
i32 runuf50();
i32 runuuf50();