| ... | @@ -9,26 +9,45 @@ const mem = std.mem; | ... | @@ -9,26 +9,45 @@ const mem = std.mem; |
| 9 | test "@addWithOverflow" { | 9 | test "@addWithOverflow" { |
| 10 | var result: u8 = undefined; | 10 | var result: u8 = undefined; |
| 11 | try expect(@addWithOverflow(u8, 250, 100, &result)); | 11 | try expect(@addWithOverflow(u8, 250, 100, &result)); |
| | 12 | try expect(result == 94); |
| 12 | try expect(!@addWithOverflow(u8, 100, 150, &result)); | 13 | try expect(!@addWithOverflow(u8, 100, 150, &result)); |
| 13 | try expect(result == 250); | 14 | try expect(result == 250); |
| 14 | } | 15 | } |
| 15 | | 16 | |
| 16 | // TODO test mulWithOverflow | 17 | test "@mulWithOverflow" { |
| 17 | // TODO test subWithOverflow | 18 | var result: u8 = undefined; |
| | 19 | try expect(@mulWithOverflow(u8, 86, 3, &result)); |
| | 20 | try expect(result == 2); |
| | 21 | try expect(!@mulWithOverflow(u8, 85, 3, &result)); |
| | 22 | try expect(result == 255); |
| | 23 | } |
| | 24 | |
| | 25 | test "@subWithOverflow" { |
| | 26 | var result: u8 = undefined; |
| | 27 | try expect(@subWithOverflow(u8, 1, 2, &result)); |
| | 28 | try expect(result == 255); |
| | 29 | try expect(!@subWithOverflow(u8, 1, 1, &result)); |
| | 30 | try expect(result == 0); |
| | 31 | } |
| 18 | | 32 | |
| 19 | test "@shlWithOverflow" { | 33 | test "@shlWithOverflow" { |
| 20 | var result: u16 = undefined; | 34 | var result: u16 = undefined; |
| 21 | try expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result)); | 35 | try expect(@shlWithOverflow(u16, 0b0010111111111111, 3, &result)); |
| | 36 | try expect(result == 0b0111111111111000); |
| 22 | try expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result)); | 37 | try expect(!@shlWithOverflow(u16, 0b0010111111111111, 2, &result)); |
| 23 | try expect(result == 0b1011111111111100); | 38 | try expect(result == 0b1011111111111100); |
| 24 | } | 39 | } |
| 25 | | 40 | |
| 26 | test "@*WithOverflow with u0 values" { | 41 | test "overflow arithmetic with u0 values" { |
| 27 | var result: u0 = undefined; | 42 | var result: u0 = undefined; |
| 28 | try expect(!@addWithOverflow(u0, 0, 0, &result)); | 43 | try expect(!@addWithOverflow(u0, 0, 0, &result)); |
| | 44 | try expect(result == 0); |
| 29 | try expect(!@subWithOverflow(u0, 0, 0, &result)); | 45 | try expect(!@subWithOverflow(u0, 0, 0, &result)); |
| | 46 | try expect(result == 0); |
| 30 | try expect(!@mulWithOverflow(u0, 0, 0, &result)); | 47 | try expect(!@mulWithOverflow(u0, 0, 0, &result)); |
| | 48 | try expect(result == 0); |
| 31 | try expect(!@shlWithOverflow(u0, 0, 0, &result)); | 49 | try expect(!@shlWithOverflow(u0, 0, 0, &result)); |
| | 50 | try expect(result == 0); |
| 32 | } | 51 | } |
| 33 | | 52 | |
| 34 | test "@clz vectors" { | 53 | test "@clz vectors" { |