zig/lib/compiler_rt/cmpsi2_test.zig
Andrew Kelley ec95e00e28 flatten lib/std/special and improve "pkg inside another" logic
stage2: change logic for detecting whether the main package is inside
the std package. Previously it relied on realpath() which is not portable.
This uses resolve() which is how imports already work.

 * stage2: fix cleanup bug when creating Module
 * flatten lib/std/special/* to lib/*
   - this was motivated by making main_pkg_is_inside_std false for
     compiler_rt & friends.
 * rename "mini libc" to "universal libc"
2022-05-06 22:41:00 -07:00

106 lines
4.7 KiB
Zig

const cmp = @import("cmp.zig");
const testing = @import("std").testing;
fn test__cmpsi2(a: i32, b: i32, expected: i32) !void {
var result = cmp.__cmpsi2(a, b);
try testing.expectEqual(expected, result);
}
test "cmpsi2" {
// minInt == -2147483648
// maxInt == 2147483647
// minInt/2 == -1073741824
// maxInt/2 == 1073741823
// 1. equality minInt, minInt+1, minInt/2, -1, 0, 1, maxInt/2, maxInt-1, maxInt
try test__cmpsi2(-2147483648, -2147483648, 1);
try test__cmpsi2(-2147483647, -2147483647, 1);
try test__cmpsi2(-1073741824, -1073741824, 1);
try test__cmpsi2(-1, -1, 1);
try test__cmpsi2(0, 0, 1);
try test__cmpsi2(1, 1, 1);
try test__cmpsi2(1073741823, 1073741823, 1);
try test__cmpsi2(2147483646, 2147483646, 1);
try test__cmpsi2(2147483647, 2147483647, 1);
// 2. cmp minInt, { minInt + 1, minInt/2, -1,0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpsi2(-2147483648, -2147483647, 0);
try test__cmpsi2(-2147483648, -1073741824, 0);
try test__cmpsi2(-2147483648, -1, 0);
try test__cmpsi2(-2147483648, 0, 0);
try test__cmpsi2(-2147483648, 1, 0);
try test__cmpsi2(-2147483648, 1073741823, 0);
try test__cmpsi2(-2147483648, 2147483646, 0);
try test__cmpsi2(-2147483648, 2147483647, 0);
// 3. cmp minInt+1, {minInt, minInt/2, -1,0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpsi2(-2147483647, -2147483648, 2);
try test__cmpsi2(-2147483647, -1073741824, 0);
try test__cmpsi2(-2147483647, -1, 0);
try test__cmpsi2(-2147483647, 0, 0);
try test__cmpsi2(-2147483647, 1, 0);
try test__cmpsi2(-2147483647, 1073741823, 0);
try test__cmpsi2(-2147483647, 2147483646, 0);
try test__cmpsi2(-2147483647, 2147483647, 0);
// 4. cmp minInt/2, {minInt, minInt + 1, -1,0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpsi2(-1073741824, -2147483648, 2);
try test__cmpsi2(-1073741824, -2147483647, 2);
try test__cmpsi2(-1073741824, -1, 0);
try test__cmpsi2(-1073741824, 0, 0);
try test__cmpsi2(-1073741824, 1, 0);
try test__cmpsi2(-1073741824, 1073741823, 0);
try test__cmpsi2(-1073741824, 2147483646, 0);
try test__cmpsi2(-1073741824, 2147483647, 0);
// 5. cmp -1, {minInt, minInt + 1, minInt/2, 0,1, maxInt/2, maxInt-1, maxInt}
try test__cmpsi2(-1, -2147483648, 2);
try test__cmpsi2(-1, -2147483647, 2);
try test__cmpsi2(-1, -1073741824, 2);
try test__cmpsi2(-1, 0, 0);
try test__cmpsi2(-1, 1, 0);
try test__cmpsi2(-1, 1073741823, 0);
try test__cmpsi2(-1, 2147483646, 0);
try test__cmpsi2(-1, 2147483647, 0);
// 6. cmp 0, {minInt, minInt + 1, minInt/2, -1, 1, maxInt/2, maxInt-1, maxInt}
try test__cmpsi2(0, -2147483648, 2);
try test__cmpsi2(0, -2147483647, 2);
try test__cmpsi2(0, -1073741824, 2);
try test__cmpsi2(0, -1, 2);
try test__cmpsi2(0, 1, 0);
try test__cmpsi2(0, 1073741823, 0);
try test__cmpsi2(0, 2147483646, 0);
try test__cmpsi2(0, 2147483647, 0);
// 7. cmp 1, {minInt, minInt + 1, minInt/2, -1,0, maxInt/2, maxInt-1, maxInt}
try test__cmpsi2(1, -2147483648, 2);
try test__cmpsi2(1, -2147483647, 2);
try test__cmpsi2(1, -1073741824, 2);
try test__cmpsi2(1, -1, 2);
try test__cmpsi2(1, 0, 2);
try test__cmpsi2(1, 1073741823, 0);
try test__cmpsi2(1, 2147483646, 0);
try test__cmpsi2(1, 2147483647, 0);
// 8. cmp maxInt/2, {minInt, minInt + 1, minInt/2, -1, 0, 1, maxInt-1, maxInt}
try test__cmpsi2(1073741823, -2147483648, 2);
try test__cmpsi2(1073741823, -2147483647, 2);
try test__cmpsi2(1073741823, -1073741824, 2);
try test__cmpsi2(1073741823, -1, 2);
try test__cmpsi2(1073741823, 0, 2);
try test__cmpsi2(1073741823, 1, 2);
try test__cmpsi2(1073741823, 2147483646, 0);
try test__cmpsi2(1073741823, 2147483647, 0);
// 9. cmp maxInt-1, {minInt, minInt + 1, minInt/2, -1, 0, 1, maxInt/2, maxInt}
try test__cmpsi2(2147483646, -2147483648, 2);
try test__cmpsi2(2147483646, -2147483647, 2);
try test__cmpsi2(2147483646, -1073741824, 2);
try test__cmpsi2(2147483646, -1, 2);
try test__cmpsi2(2147483646, 0, 2);
try test__cmpsi2(2147483646, 1, 2);
try test__cmpsi2(2147483646, 1073741823, 2);
try test__cmpsi2(2147483646, 2147483647, 0);
// 10.cmp maxInt, {minInt, minInt + 1, minInt/2, -1, 0, 1, maxInt/2, maxInt-1, }
try test__cmpsi2(2147483647, -2147483648, 2);
try test__cmpsi2(2147483647, -2147483647, 2);
try test__cmpsi2(2147483647, -1073741824, 2);
try test__cmpsi2(2147483647, -1, 2);
try test__cmpsi2(2147483647, 0, 2);
try test__cmpsi2(2147483647, 1, 2);
try test__cmpsi2(2147483647, 1073741823, 2);
try test__cmpsi2(2147483647, 2147483646, 2);
}