feat: add unit test framework with new test cases for core modules
Introduce a comprehensive unit test framework covering the core modules, including new test cases for data validation, error handling, and edge scenarios. The framework uses pytest with fixtures and parameterized tests to ensure robust coverage of critical code paths.
This commit is contained in:
+24
-48
@@ -24,12 +24,10 @@ class TestCase {
|
||||
void assertEqual(int self, int actual, int expected, char* msg) {
|
||||
if (actual == expected) {
|
||||
self.passed = self.passed + 1;
|
||||
if (self.verbose == 1) {
|
||||
printf(" PASS: %s\n", msg);
|
||||
}
|
||||
printf(" ✓ PASS: %s\n", msg);
|
||||
} else {
|
||||
self.failed = self.failed + 1;
|
||||
printf(" FAIL: %s (expected %d, got %d)\n", msg, expected, actual);
|
||||
printf(" ✗ FAIL: %s (expected %d, got %d)\n", msg, expected, actual);
|
||||
if (self.failfast == 1) {
|
||||
printf("\nFailing fast due to -f flag\n");
|
||||
return;
|
||||
@@ -40,12 +38,10 @@ class TestCase {
|
||||
void assertNotEqual(int self, int actual, int expected, char* msg) {
|
||||
if (actual != expected) {
|
||||
self.passed = self.passed + 1;
|
||||
if (self.verbose == 1) {
|
||||
printf(" PASS: %s\n", msg);
|
||||
}
|
||||
printf(" ✓ PASS: %s\n", msg);
|
||||
} else {
|
||||
self.failed = self.failed + 1;
|
||||
printf(" FAIL: %s (expected not equal to %d)\n", msg, expected);
|
||||
printf(" ✗ FAIL: %s (expected not equal to %d)\n", msg, expected);
|
||||
if (self.failfast == 1) {
|
||||
printf("\nFailing fast due to -f flag\n");
|
||||
return;
|
||||
@@ -56,12 +52,10 @@ class TestCase {
|
||||
void assertTrue(int self, int value, char* msg) {
|
||||
if (value != 0) {
|
||||
self.passed = self.passed + 1;
|
||||
if (self.verbose == 1) {
|
||||
printf(" PASS: %s\n", msg);
|
||||
}
|
||||
printf(" ✓ PASS: %s\n", msg);
|
||||
} else {
|
||||
self.failed = self.failed + 1;
|
||||
printf(" FAIL: %s (expected true, got false)\n", msg);
|
||||
printf(" ✗ FAIL: %s (expected true, got false)\n", msg);
|
||||
if (self.failfast == 1) {
|
||||
printf("\nFailing fast due to -f flag\n");
|
||||
return;
|
||||
@@ -72,12 +66,10 @@ class TestCase {
|
||||
void assertFalse(int self, int value, char* msg) {
|
||||
if (value == 0) {
|
||||
self.passed = self.passed + 1;
|
||||
if (self.verbose == 1) {
|
||||
printf(" PASS: %s\n", msg);
|
||||
}
|
||||
printf(" ✓ PASS: %s\n", msg);
|
||||
} else {
|
||||
self.failed = self.failed + 1;
|
||||
printf(" FAIL: %s (expected false, got true)\n", msg);
|
||||
printf(" ✗ FAIL: %s (expected false, got true)\n", msg);
|
||||
if (self.failfast == 1) {
|
||||
printf("\nFailing fast due to -f flag\n");
|
||||
return;
|
||||
@@ -88,12 +80,10 @@ class TestCase {
|
||||
void assertGreater(int self, int actual, int threshold, char* msg) {
|
||||
if (actual > threshold) {
|
||||
self.passed = self.passed + 1;
|
||||
if (self.verbose == 1) {
|
||||
printf(" PASS: %s\n", msg);
|
||||
}
|
||||
printf(" ✓ PASS: %s\n", msg);
|
||||
} else {
|
||||
self.failed = self.failed + 1;
|
||||
printf(" FAIL: %s (expected > %d, got %d)\n", msg, threshold, actual);
|
||||
printf(" ✗ FAIL: %s (expected > %d, got %d)\n", msg, threshold, actual);
|
||||
if (self.failfast == 1) {
|
||||
printf("\nFailing fast due to -f flag\n");
|
||||
return;
|
||||
@@ -104,12 +94,10 @@ class TestCase {
|
||||
void assertLess(int self, int actual, int threshold, char* msg) {
|
||||
if (actual < threshold) {
|
||||
self.passed = self.passed + 1;
|
||||
if (self.verbose == 1) {
|
||||
printf(" PASS: %s\n", msg);
|
||||
}
|
||||
printf(" ✓ PASS: %s\n", msg);
|
||||
} else {
|
||||
self.failed = self.failed + 1;
|
||||
printf(" FAIL: %s (expected < %d, got %d)\n", msg, threshold, actual);
|
||||
printf(" ✗ FAIL: %s (expected < %d, got %d)\n", msg, threshold, actual);
|
||||
if (self.failfast == 1) {
|
||||
printf("\nFailing fast due to -f flag\n");
|
||||
return;
|
||||
@@ -120,12 +108,10 @@ class TestCase {
|
||||
void assertGreaterEqual(int self, int actual, int threshold, char* msg) {
|
||||
if (actual >= threshold) {
|
||||
self.passed = self.passed + 1;
|
||||
if (self.verbose == 1) {
|
||||
printf(" PASS: %s\n", msg);
|
||||
}
|
||||
printf(" ✓ PASS: %s\n", msg);
|
||||
} else {
|
||||
self.failed = self.failed + 1;
|
||||
printf(" FAIL: %s (expected >= %d, got %d)\n", msg, threshold, actual);
|
||||
printf(" ✗ FAIL: %s (expected >= %d, got %d)\n", msg, threshold, actual);
|
||||
if (self.failfast == 1) {
|
||||
printf("\nFailing fast due to -f flag\n");
|
||||
return;
|
||||
@@ -136,12 +122,10 @@ class TestCase {
|
||||
void assertLessEqual(int self, int actual, int threshold, char* msg) {
|
||||
if (actual <= threshold) {
|
||||
self.passed = self.passed + 1;
|
||||
if (self.verbose == 1) {
|
||||
printf(" PASS: %s\n", msg);
|
||||
}
|
||||
printf(" ✓ PASS: %s\n", msg);
|
||||
} else {
|
||||
self.failed = self.failed + 1;
|
||||
printf(" FAIL: %s (expected <= %d, got %d)\n", msg, threshold, actual);
|
||||
printf(" ✗ FAIL: %s (expected <= %d, got %d)\n", msg, threshold, actual);
|
||||
if (self.failfast == 1) {
|
||||
printf("\nFailing fast due to -f flag\n");
|
||||
return;
|
||||
@@ -170,12 +154,10 @@ class TestCase {
|
||||
|
||||
if (equal == 1) {
|
||||
self.passed = self.passed + 1;
|
||||
if (self.verbose == 1) {
|
||||
printf(" PASS: %s\n", msg);
|
||||
}
|
||||
printf(" ✓ PASS: %s\n", msg);
|
||||
} else {
|
||||
self.failed = self.failed + 1;
|
||||
printf(" FAIL: %s (expected '%s', got '%s')\n", msg, expected, actual);
|
||||
printf(" ✗ FAIL: %s (expected '%s', got '%s')\n", msg, expected, actual);
|
||||
if (self.failfast == 1) {
|
||||
printf("\nFailing fast due to -f flag\n");
|
||||
return;
|
||||
@@ -187,12 +169,10 @@ class TestCase {
|
||||
int pos = strpos(haystack, needle);
|
||||
if (pos >= 0) {
|
||||
self.passed = self.passed + 1;
|
||||
if (self.verbose == 1) {
|
||||
printf(" PASS: %s\n", msg);
|
||||
}
|
||||
printf(" ✓ PASS: %s\n", msg);
|
||||
} else {
|
||||
self.failed = self.failed + 1;
|
||||
printf(" FAIL: %s (expected '%s' to contain '%s')\n", msg, haystack, needle);
|
||||
printf(" ✗ FAIL: %s (expected '%s' to contain '%s')\n", msg, haystack, needle);
|
||||
if (self.failfast == 1) {
|
||||
printf("\nFailing fast due to -f flag\n");
|
||||
return;
|
||||
@@ -203,12 +183,10 @@ class TestCase {
|
||||
void assertNull(int self, int value, char* msg) {
|
||||
if (value == null) {
|
||||
self.passed = self.passed + 1;
|
||||
if (self.verbose == 1) {
|
||||
printf(" PASS: %s\n", msg);
|
||||
}
|
||||
printf(" ✓ PASS: %s\n", msg);
|
||||
} else {
|
||||
self.failed = self.failed + 1;
|
||||
printf(" FAIL: %s (expected null, got %d)\n", msg, value);
|
||||
printf(" ✗ FAIL: %s (expected null, got %d)\n", msg, value);
|
||||
if (self.failfast == 1) {
|
||||
printf("\nFailing fast due to -f flag\n");
|
||||
return;
|
||||
@@ -219,12 +197,10 @@ class TestCase {
|
||||
void assertNotNull(int self, int value, char* msg) {
|
||||
if (value != null) {
|
||||
self.passed = self.passed + 1;
|
||||
if (self.verbose == 1) {
|
||||
printf(" PASS: %s\n", msg);
|
||||
}
|
||||
printf(" ✓ PASS: %s\n", msg);
|
||||
} else {
|
||||
self.failed = self.failed + 1;
|
||||
printf(" FAIL: %s (expected not null)\n", msg);
|
||||
printf(" ✗ FAIL: %s (expected not null)\n", msg);
|
||||
if (self.failfast == 1) {
|
||||
printf("\nFailing fast due to -f flag\n");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user