From 8996ee7580ed85b42b6399f9f64e29092ce21c41 Mon Sep 17 00:00:00 2001 From: axtlos Date: Mon, 23 Sep 2024 23:01:51 +0200 Subject: Add cap,min,max functions --- tests/test.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'tests') diff --git a/tests/test.c b/tests/test.c index 332ebb8..0d1ff7c 100644 --- a/tests/test.c +++ b/tests/test.c @@ -6,6 +6,38 @@ #define USE_SECURE_MEM #include "../src/extlib.h" +int +test_min_max_cap () +{ + int val = 5; + int max_v = 10; + int min_v = 1; + if (cap(val, min_v, max_v) != 5) + return 1; + if (max(val, max_v) != 5) + return 2; + if (min(val, min_v) != 5) + return 3; + + val = 11; + if (cap(val, min_v, max_v) != 10) + return 4; + if (max(val, max_v) != 10) + return 5; + if (min(val, min_v) != 11) + return 6; + + val = 0; + if (cap(val, min_v, max_v) != 1) + return 7; + if (max(val, max_v) != 0) + return 8; + if (min(val, min_v) != 1) + return 9; + + return 0; +} + int test_malloc_free_secure (size_t size) { @@ -178,5 +210,12 @@ main (void) printf ("Test Case 6: test_join_str -- SUCCESS\n\n"); else printf ("Test Case 6: test_join_str -- FAILED %d\n\n", test_6_result); + + printf ("Test Case 7: test_min_max_cap\n"); + int test_7_result = test_min_max_cap (); + if (test_7_result == 0) + printf ("Test Case 7: test_min_max_cap -- SUCCESS\n\n"); + else + printf ("Test Case 7: test_min_max_cap -- FAILED %d\n\n", test_7_result); return 0; } -- cgit v1.2.3