Skip to content

Commit 9fa5bf2

Browse files
author
Thomas Kiley
committed
Add test for different sized arrays
__CPROVER_array_equal should be able verify that arrays of different size or type are never equal, and the assert should verify.
1 parent 8b0d2ad commit 9fa5bf2

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

regression/cbmc/Array_operations1/main.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ void test_equal()
1212
__CPROVER_assert(array1[index] == array2[index], "arrays are equal");
1313
}
1414

15+
void test_unequal()
16+
{
17+
int a1[10];
18+
int a2[16];
19+
20+
__CPROVER_assert(
21+
!__CPROVER_array_equal(a1, a2), "different sizes arrays are unequal");
22+
23+
float a3[10];
24+
void *lost_type1 = a1;
25+
void *lost_type3 = a3;
26+
27+
__CPROVER_assert(
28+
!__CPROVER_array_equal(lost_type1, lost_type3),
29+
"different typed arrays are unequal");
30+
}
31+
1532
void test_copy()
1633
{
1734
char array1[100], array2[100], array3[90];
@@ -54,4 +71,5 @@ int main()
5471
test_copy();
5572
test_replace();
5673
test_set();
74+
test_unequal();
5775
}

regression/cbmc/Array_operations1/test.desc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ main.c
44
^EXIT=10$
55
^SIGNAL=0$
66
^\[test_copy\.assertion\.4\] .* expected to fail: FAILURE$
7-
^\*\* 1 of 8 failed
7+
^\[test_unequal\.assertion\.1\] .* different sizes arrays are unequal: SUCCESS
8+
^\[test_unequal\.assertion\.2\] .* different typed arrays are unequal: SUCCESS
9+
^\*\* 1 of 10 failed
810
^VERIFICATION FAILED$
911
--
1012
^warning: ignoring

0 commit comments

Comments
 (0)