Convert tests to use `assert` keyword
7fa02c340215a655d710769ccd247278ed5e8d83885390aecb6565cf81304df6
1 parent
7a8ab6ad
lib/std/arch/rv64/tests/abi.sizes.rad
+18 -54
| 65 | 65 | } |
|
| 66 | 66 | ||
| 67 | 67 | /// Test 1-byte record. |
|
| 68 | 68 | fn testByte() -> i32 { |
|
| 69 | 69 | let b = makeByte(42); |
|
| 70 | - | if b.x != 42 { |
|
| 71 | - | return 1; |
|
| 72 | - | } |
|
| 70 | + | assert b.x == 42; |
|
| 73 | 71 | return 0; |
|
| 74 | 72 | } |
|
| 75 | 73 | ||
| 76 | 74 | /// Test 2-byte record. |
|
| 77 | 75 | fn testShort() -> i32 { |
|
| 78 | 76 | let s = makeShort(1234); |
|
| 79 | - | if s.x != 1234 { |
|
| 80 | - | return 1; |
|
| 81 | - | } |
|
| 77 | + | assert s.x == 1234; |
|
| 82 | 78 | return 0; |
|
| 83 | 79 | } |
|
| 84 | 80 | ||
| 85 | 81 | /// Test 4-byte record. |
|
| 86 | 82 | fn testWord() -> i32 { |
|
| 87 | 83 | let w = makeWord(0xDEAD); |
|
| 88 | - | if w.x != 0xDEAD { |
|
| 89 | - | return 1; |
|
| 90 | - | } |
|
| 84 | + | assert w.x == 0xDEAD; |
|
| 91 | 85 | return 0; |
|
| 92 | 86 | } |
|
| 93 | 87 | ||
| 94 | 88 | /// Test 8-byte record (boundary case, should be by value). |
|
| 95 | 89 | fn testPair() -> i32 { |
|
| 96 | 90 | let p = makePair(10, 20); |
|
| 97 | - | if p.a != 10 { |
|
| 98 | - | return 1; |
|
| 99 | - | } |
|
| 100 | - | if p.b != 20 { |
|
| 101 | - | return 2; |
|
| 102 | - | } |
|
| 91 | + | assert p.a == 10; |
|
| 92 | + | assert p.b == 20; |
|
| 103 | 93 | return 0; |
|
| 104 | 94 | } |
|
| 105 | 95 | ||
| 106 | 96 | /// Test 12-byte record (should be by reference). |
|
| 107 | 97 | fn testTriple() -> i32 { |
|
| 108 | 98 | let t = makeTriple(100, 200, 300); |
|
| 109 | - | if t.x != 100 { |
|
| 110 | - | return 1; |
|
| 111 | - | } |
|
| 112 | - | if t.y != 200 { |
|
| 113 | - | return 2; |
|
| 114 | - | } |
|
| 115 | - | if t.z != 300 { |
|
| 116 | - | return 3; |
|
| 117 | - | } |
|
| 99 | + | assert t.x == 100; |
|
| 100 | + | assert t.y == 200; |
|
| 101 | + | assert t.z == 300; |
|
| 118 | 102 | return 0; |
|
| 119 | 103 | } |
|
| 120 | 104 | ||
| 121 | 105 | /// Test passing small aggregate as parameter and returning it. |
|
| 122 | 106 | fn testIdentity() -> i32 { |
|
| 123 | 107 | let p = makePair(5, 6); |
|
| 124 | 108 | let q = identity(p); |
|
| 125 | - | if q.a != 5 { |
|
| 126 | - | return 1; |
|
| 127 | - | } |
|
| 128 | - | if q.b != 6 { |
|
| 129 | - | return 2; |
|
| 130 | - | } |
|
| 109 | + | assert q.a == 5; |
|
| 110 | + | assert q.b == 6; |
|
| 131 | 111 | return 0; |
|
| 132 | 112 | } |
|
| 133 | 113 | ||
| 134 | 114 | /// Test multiple small aggregate args. |
|
| 135 | 115 | fn testAddPairs() -> i32 { |
|
| 136 | 116 | let a = makePair(1, 2); |
|
| 137 | 117 | let b = makePair(3, 4); |
|
| 138 | 118 | let c = addPairs(a, b); |
|
| 139 | - | if c.a != 4 { |
|
| 140 | - | return 1; |
|
| 141 | - | } |
|
| 142 | - | if c.b != 6 { |
|
| 143 | - | return 2; |
|
| 144 | - | } |
|
| 119 | + | assert c.a == 4; |
|
| 120 | + | assert c.b == 6; |
|
| 145 | 121 | return 0; |
|
| 146 | 122 | } |
|
| 147 | 123 | ||
| 148 | 124 | /// Test chained calls. |
|
| 149 | 125 | fn testDoublePair() -> i32 { |
|
| 150 | 126 | let p = makePair(10, 20); |
|
| 151 | 127 | let d = doublePair(p); |
|
| 152 | - | if d.a != 20 { |
|
| 153 | - | return 1; |
|
| 154 | - | } |
|
| 155 | - | if d.b != 40 { |
|
| 156 | - | return 2; |
|
| 157 | - | } |
|
| 128 | + | assert d.a == 20; |
|
| 129 | + | assert d.b == 40; |
|
| 158 | 130 | return 0; |
|
| 159 | 131 | } |
|
| 160 | 132 | ||
| 161 | 133 | /// Test multiple returns don't interfere. |
|
| 162 | 134 | fn testMultipleReturns() -> i32 { |
|
| 163 | 135 | let p1 = makePair(1, 2); |
|
| 164 | 136 | let p2 = makePair(3, 4); |
|
| 165 | - | if p1.a != 1 { |
|
| 166 | - | return 1; |
|
| 167 | - | } |
|
| 168 | - | if p1.b != 2 { |
|
| 169 | - | return 2; |
|
| 170 | - | } |
|
| 171 | - | if p2.a != 3 { |
|
| 172 | - | return 3; |
|
| 173 | - | } |
|
| 174 | - | if p2.b != 4 { |
|
| 175 | - | return 4; |
|
| 176 | - | } |
|
| 137 | + | assert p1.a == 1; |
|
| 138 | + | assert p1.b == 2; |
|
| 139 | + | assert p2.a == 3; |
|
| 140 | + | assert p2.b == 4; |
|
| 177 | 141 | return 0; |
|
| 178 | 142 | } |
|
| 179 | 143 | ||
| 180 | 144 | @default fn main() -> i32 { |
|
| 181 | 145 | let r1 = testByte(); |
lib/std/arch/rv64/tests/aggregate.return.rad
+27 -81
| 35 | 35 | fn testReturnDoesNotCorruptLocals() -> i32 { |
|
| 36 | 36 | let sentinel: u32 = 0xDEAD; |
|
| 37 | 37 | let p: Pair = makePair(10, 20); |
|
| 38 | 38 | let sentinel2: u32 = 0xBEEF; |
|
| 39 | 39 | ||
| 40 | - | if p.a != 10 { |
|
| 41 | - | return 1; |
|
| 42 | - | } |
|
| 43 | - | if p.b != 20 { |
|
| 44 | - | return 2; |
|
| 45 | - | } |
|
| 46 | - | if sentinel != 0xDEAD { |
|
| 47 | - | return 3; |
|
| 48 | - | } |
|
| 49 | - | if sentinel2 != 0xBEEF { |
|
| 50 | - | return 4; |
|
| 51 | - | } |
|
| 40 | + | assert p.a == 10; |
|
| 41 | + | assert p.b == 20; |
|
| 42 | + | assert sentinel == 0xDEAD; |
|
| 43 | + | assert sentinel2 == 0xBEEF; |
|
| 52 | 44 | return 0; |
|
| 53 | 45 | } |
|
| 54 | 46 | ||
| 55 | 47 | /// Two consecutive aggregate returns must not interfere. |
|
| 56 | 48 | fn testMultipleReturns() -> i32 { |
|
| 57 | 49 | let p1: Pair = makePair(1, 2); |
|
| 58 | 50 | let p2: Pair = makePair(3, 4); |
|
| 59 | 51 | ||
| 60 | - | if p1.a != 1 { |
|
| 61 | - | return 1; |
|
| 62 | - | } |
|
| 63 | - | if p1.b != 2 { |
|
| 64 | - | return 2; |
|
| 65 | - | } |
|
| 66 | - | if p2.a != 3 { |
|
| 67 | - | return 3; |
|
| 68 | - | } |
|
| 69 | - | if p2.b != 4 { |
|
| 70 | - | return 4; |
|
| 71 | - | } |
|
| 52 | + | assert p1.a == 1; |
|
| 53 | + | assert p1.b == 2; |
|
| 54 | + | assert p2.a == 3; |
|
| 55 | + | assert p2.b == 4; |
|
| 72 | 56 | return 0; |
|
| 73 | 57 | } |
|
| 74 | 58 | ||
| 75 | 59 | /// Mutating a returned aggregate must not corrupt the stack. |
|
| 76 | 60 | fn testMutateReturnedAggregate() -> i32 { |
| 79 | 63 | let after: u32 = 99; |
|
| 80 | 64 | ||
| 81 | 65 | p.a = 100; |
|
| 82 | 66 | p.b = 200; |
|
| 83 | 67 | ||
| 84 | - | if before != 42 { |
|
| 85 | - | return 1; |
|
| 86 | - | } |
|
| 87 | - | if after != 99 { |
|
| 88 | - | return 2; |
|
| 89 | - | } |
|
| 90 | - | if p.a != 100 { |
|
| 91 | - | return 3; |
|
| 92 | - | } |
|
| 93 | - | if p.b != 200 { |
|
| 94 | - | return 4; |
|
| 95 | - | } |
|
| 68 | + | assert before == 42; |
|
| 69 | + | assert after == 99; |
|
| 70 | + | assert p.a == 100; |
|
| 71 | + | assert p.b == 200; |
|
| 96 | 72 | return 0; |
|
| 97 | 73 | } |
|
| 98 | 74 | ||
| 99 | 75 | /// Aggregate return inside a loop must not corrupt accumulator state. |
|
| 100 | 76 | fn testAggregateReturnInLoop() -> i32 { |
| 104 | 80 | let p: Pair = makePair(idx, idx + 10); |
|
| 105 | 81 | total += p.a + p.b; |
|
| 106 | 82 | idx += 1; |
|
| 107 | 83 | } |
|
| 108 | 84 | // total = sum(i + i+10 for i in 0..5) = sum(2i+10) = 2*(0+1+2+3+4) + 50 = 20 + 50 = 70 |
|
| 109 | - | if total != 70 { |
|
| 110 | - | return 1; |
|
| 111 | - | } |
|
| 85 | + | assert total == 70; |
|
| 112 | 86 | return 0; |
|
| 113 | 87 | } |
|
| 114 | 88 | ||
| 115 | 89 | /// Throwing function returning aggregate (result buffer) must not corrupt stack. |
|
| 116 | 90 | fn testThrowingAggregateReturn() -> i32 { |
|
| 117 | 91 | let sentinel: u32 = 0xCAFE; |
|
| 118 | 92 | let p: Pair = try! makePairOrFail(10, 20, false); |
|
| 119 | 93 | let sentinel2: u32 = 0xFACE; |
|
| 120 | 94 | ||
| 121 | - | if p.a != 10 { |
|
| 122 | - | return 1; |
|
| 123 | - | } |
|
| 124 | - | if p.b != 20 { |
|
| 125 | - | return 2; |
|
| 126 | - | } |
|
| 127 | - | if sentinel != 0xCAFE { |
|
| 128 | - | return 3; |
|
| 129 | - | } |
|
| 130 | - | if sentinel2 != 0xFACE { |
|
| 131 | - | return 4; |
|
| 132 | - | } |
|
| 95 | + | assert p.a == 10; |
|
| 96 | + | assert p.b == 20; |
|
| 97 | + | assert sentinel == 0xCAFE; |
|
| 98 | + | assert sentinel2 == 0xFACE; |
|
| 133 | 99 | return 0; |
|
| 134 | 100 | } |
|
| 135 | 101 | ||
| 136 | 102 | /// Catching a thrown error from aggregate-returning function. |
|
| 137 | 103 | fn testThrowingAggregateCatch() -> i32 { |
|
| 138 | 104 | let sentinel: u32 = 0xBEEF; |
|
| 139 | 105 | try makePairOrFail(10, 20, true) catch {}; |
|
| 140 | - | if sentinel != 0xBEEF { |
|
| 141 | - | return 1; |
|
| 142 | - | } |
|
| 106 | + | assert sentinel == 0xBEEF; |
|
| 143 | 107 | return 0; |
|
| 144 | 108 | } |
|
| 145 | 109 | ||
| 146 | 110 | /// Triple (12 bytes) aggregate return. |
|
| 147 | 111 | fn testTripleReturn() -> i32 { |
|
| 148 | 112 | let t: Triple = makeTriple(100, 200, 300); |
|
| 149 | - | if t.x != 100 { |
|
| 150 | - | return 1; |
|
| 151 | - | } |
|
| 152 | - | if t.y != 200 { |
|
| 153 | - | return 2; |
|
| 154 | - | } |
|
| 155 | - | if t.z != 300 { |
|
| 156 | - | return 3; |
|
| 157 | - | } |
|
| 113 | + | assert t.x == 100; |
|
| 114 | + | assert t.y == 200; |
|
| 115 | + | assert t.z == 300; |
|
| 158 | 116 | return 0; |
|
| 159 | 117 | } |
|
| 160 | 118 | ||
| 161 | 119 | /// Multiple aggregate calls interleaved with scalar work. |
|
| 162 | 120 | fn testInterleavedCalls() -> i32 { |
|
| 163 | 121 | let p1: Pair = makePair(5, 6); |
|
| 164 | 122 | let scalar: u32 = p1.a + p1.b; |
|
| 165 | 123 | let t: Triple = makeTriple(scalar, scalar + 1, scalar + 2); |
|
| 166 | 124 | let p2: Pair = makePair(t.x, t.z); |
|
| 167 | 125 | ||
| 168 | - | if scalar != 11 { |
|
| 169 | - | return 1; |
|
| 170 | - | } |
|
| 171 | - | if t.x != 11 { |
|
| 172 | - | return 2; |
|
| 173 | - | } |
|
| 174 | - | if t.y != 12 { |
|
| 175 | - | return 3; |
|
| 176 | - | } |
|
| 177 | - | if t.z != 13 { |
|
| 178 | - | return 4; |
|
| 179 | - | } |
|
| 180 | - | if p2.a != 11 { |
|
| 181 | - | return 5; |
|
| 182 | - | } |
|
| 183 | - | if p2.b != 13 { |
|
| 184 | - | return 6; |
|
| 185 | - | } |
|
| 126 | + | assert scalar == 11; |
|
| 127 | + | assert t.x == 11; |
|
| 128 | + | assert t.y == 12; |
|
| 129 | + | assert t.z == 13; |
|
| 130 | + | assert p2.a == 11; |
|
| 131 | + | assert p2.b == 13; |
|
| 186 | 132 | return 0; |
|
| 187 | 133 | } |
|
| 188 | 134 | ||
| 189 | 135 | @default fn main() -> i32 { |
|
| 190 | 136 | let r1: i32 = testReturnDoesNotCorruptLocals(); |
lib/std/arch/rv64/tests/arith.subword.rad
+15 -45
| 162 | 162 | } |
|
| 163 | 163 | return true; |
|
| 164 | 164 | } |
|
| 165 | 165 | ||
| 166 | 166 | @default fn main() -> i32 { |
|
| 167 | - | if not testI8Overflow() { |
|
| 168 | - | return 1; |
|
| 169 | - | } |
|
| 170 | - | if not testU8Overflow() { |
|
| 171 | - | return 2; |
|
| 172 | - | } |
|
| 173 | - | if not testI8Subtraction() { |
|
| 174 | - | return 3; |
|
| 175 | - | } |
|
| 176 | - | if not testU8Subtraction() { |
|
| 177 | - | return 4; |
|
| 178 | - | } |
|
| 179 | - | if not testI16Overflow() { |
|
| 180 | - | return 5; |
|
| 181 | - | } |
|
| 182 | - | if not testU16Overflow() { |
|
| 183 | - | return 6; |
|
| 184 | - | } |
|
| 185 | - | if not testI8Multiply() { |
|
| 186 | - | return 7; |
|
| 187 | - | } |
|
| 188 | - | if not testU8Multiply() { |
|
| 189 | - | return 8; |
|
| 190 | - | } |
|
| 191 | - | if not testI8Comparison() { |
|
| 192 | - | return 9; |
|
| 193 | - | } |
|
| 194 | - | if not testU8Comparison() { |
|
| 195 | - | return 10; |
|
| 196 | - | } |
|
| 197 | - | if not testNarrowingCast() { |
|
| 198 | - | return 11; |
|
| 199 | - | } |
|
| 200 | - | if not testW32ShiftRight() { |
|
| 201 | - | return 12; |
|
| 202 | - | } |
|
| 203 | - | if not testI8NegOverflow() { |
|
| 204 | - | return 13; |
|
| 205 | - | } |
|
| 206 | - | if not testU8BitNot() { |
|
| 207 | - | return 14; |
|
| 208 | - | } |
|
| 209 | - | if not testW32ShiftLargeImmediate() { |
|
| 210 | - | return 15; |
|
| 211 | - | } |
|
| 167 | + | assert testI8Overflow(); |
|
| 168 | + | assert testU8Overflow(); |
|
| 169 | + | assert testI8Subtraction(); |
|
| 170 | + | assert testU8Subtraction(); |
|
| 171 | + | assert testI16Overflow(); |
|
| 172 | + | assert testU16Overflow(); |
|
| 173 | + | assert testI8Multiply(); |
|
| 174 | + | assert testU8Multiply(); |
|
| 175 | + | assert testI8Comparison(); |
|
| 176 | + | assert testU8Comparison(); |
|
| 177 | + | assert testNarrowingCast(); |
|
| 178 | + | assert testW32ShiftRight(); |
|
| 179 | + | assert testI8NegOverflow(); |
|
| 180 | + | assert testU8BitNot(); |
|
| 181 | + | assert testW32ShiftLargeImmediate(); |
|
| 212 | 182 | return 0; |
|
| 213 | 183 | } |
lib/std/arch/rv64/tests/arith.w64.rad
+18 -54
| 195 | 195 | } |
|
| 196 | 196 | return true; |
|
| 197 | 197 | } |
|
| 198 | 198 | ||
| 199 | 199 | @default fn main() -> i32 { |
|
| 200 | - | if not testI64Add() { |
|
| 201 | - | return 1; |
|
| 202 | - | } |
|
| 203 | - | if not testU64Add() { |
|
| 204 | - | return 2; |
|
| 205 | - | } |
|
| 206 | - | if not testI64Sub() { |
|
| 207 | - | return 3; |
|
| 208 | - | } |
|
| 209 | - | if not testI64Mul() { |
|
| 210 | - | return 4; |
|
| 211 | - | } |
|
| 212 | - | if not testI64Div() { |
|
| 213 | - | return 5; |
|
| 214 | - | } |
|
| 215 | - | if not testU64Div() { |
|
| 216 | - | return 6; |
|
| 217 | - | } |
|
| 218 | - | if not testI64Neg() { |
|
| 219 | - | return 7; |
|
| 220 | - | } |
|
| 221 | - | if not testI64Shift() { |
|
| 222 | - | return 8; |
|
| 223 | - | } |
|
| 224 | - | if not testU64Shift() { |
|
| 225 | - | return 9; |
|
| 226 | - | } |
|
| 227 | - | if not testI64Bitwise() { |
|
| 228 | - | return 10; |
|
| 229 | - | } |
|
| 230 | - | if not testWidenI32ToI64() { |
|
| 231 | - | return 11; |
|
| 232 | - | } |
|
| 233 | - | if not testWidenU32ToU64() { |
|
| 234 | - | return 12; |
|
| 235 | - | } |
|
| 236 | - | if not testNarrowI64ToI32() { |
|
| 237 | - | return 13; |
|
| 238 | - | } |
|
| 239 | - | if not testNarrowU64ToU32() { |
|
| 240 | - | return 14; |
|
| 241 | - | } |
|
| 242 | - | if not testI64Compare() { |
|
| 243 | - | return 15; |
|
| 244 | - | } |
|
| 245 | - | if not testU64Compare() { |
|
| 246 | - | return 16; |
|
| 247 | - | } |
|
| 248 | - | if not testI64Modulo() { |
|
| 249 | - | return 17; |
|
| 250 | - | } |
|
| 251 | - | if not testU64Modulo() { |
|
| 252 | - | return 18; |
|
| 253 | - | } |
|
| 200 | + | assert testI64Add(); |
|
| 201 | + | assert testU64Add(); |
|
| 202 | + | assert testI64Sub(); |
|
| 203 | + | assert testI64Mul(); |
|
| 204 | + | assert testI64Div(); |
|
| 205 | + | assert testU64Div(); |
|
| 206 | + | assert testI64Neg(); |
|
| 207 | + | assert testI64Shift(); |
|
| 208 | + | assert testU64Shift(); |
|
| 209 | + | assert testI64Bitwise(); |
|
| 210 | + | assert testWidenI32ToI64(); |
|
| 211 | + | assert testWidenU32ToU64(); |
|
| 212 | + | assert testNarrowI64ToI32(); |
|
| 213 | + | assert testNarrowU64ToU32(); |
|
| 214 | + | assert testI64Compare(); |
|
| 215 | + | assert testU64Compare(); |
|
| 216 | + | assert testI64Modulo(); |
|
| 217 | + | assert testU64Modulo(); |
|
| 254 | 218 | return 0; |
|
| 255 | 219 | } |
lib/std/arch/rv64/tests/array.index.assign.rad
+1 -3
| 15 | 15 | sum += arr[1]; |
|
| 16 | 16 | sum += arr[2]; |
|
| 17 | 17 | sum += arr[3]; |
|
| 18 | 18 | sum -= arr[4]; |
|
| 19 | 19 | ||
| 20 | - | if sum != 50 { |
|
| 21 | - | return 1; |
|
| 22 | - | } |
|
| 20 | + | assert sum == 50; |
|
| 23 | 21 | return 0; |
|
| 24 | 22 | } |
lib/std/arch/rv64/tests/array.slice.rad
+7 -21
| 6 | 6 | let slice1: *[i32] = &arr[..]; |
|
| 7 | 7 | let slice2: *[i32] = &arr[1..4]; |
|
| 8 | 8 | let slice3: *[i32] = &arr[..3]; |
|
| 9 | 9 | let slice4: *[i32] = &arr[2..]; |
|
| 10 | 10 | ||
| 11 | - | if slice1.len != 5 { |
|
| 12 | - | return 1; |
|
| 13 | - | } |
|
| 14 | - | if slice2.len != 3 { |
|
| 15 | - | return 2; |
|
| 16 | - | } |
|
| 17 | - | if slice3.len != 3 { |
|
| 18 | - | return 3; |
|
| 19 | - | } |
|
| 20 | - | if slice4.len != 3 { |
|
| 21 | - | return 4; |
|
| 22 | - | } |
|
| 11 | + | assert slice1.len == 5; |
|
| 12 | + | assert slice2.len == 3; |
|
| 13 | + | assert slice3.len == 3; |
|
| 14 | + | assert slice4.len == 3; |
|
| 23 | 15 | ||
| 24 | 16 | let slice5: *[i32] = slice3; |
|
| 25 | 17 | ||
| 26 | - | if slice5.len != 3 { |
|
| 27 | - | return 5; |
|
| 28 | - | } |
|
| 29 | - | if slice5.ptr != slice3.ptr { |
|
| 30 | - | return 6; |
|
| 31 | - | } |
|
| 18 | + | assert slice5.len == 3; |
|
| 19 | + | assert slice5.ptr == slice3.ptr; |
|
| 32 | 20 | ||
| 33 | 21 | let sum1: i32 = slice1[0] + slice1[4]; // 6 |
|
| 34 | 22 | let sum2: i32 = slice2[0] + slice2[1]; // 5 |
|
| 35 | 23 | let sum3: i32 = slice3[0] + slice3[2]; // 4 |
|
| 36 | 24 | let sum4: i32 = slice4[0] + slice4[2]; // 8 |
|
| 37 | 25 | ||
| 38 | 26 | let total: i32 = sum1 + sum2 + sum3 + sum4; |
|
| 39 | - | if total != 23 { |
|
| 40 | - | return 7; |
|
| 41 | - | } |
|
| 27 | + | assert total == 23; |
|
| 42 | 28 | ||
| 43 | 29 | return 0; |
|
| 44 | 30 | } |
lib/std/arch/rv64/tests/binop.bitwise.rad
+10 -30
| 1 | 1 | @default fn main() -> i32 { |
|
| 2 | 2 | // Test `&` (bitwise AND). |
|
| 3 | 3 | // `12 = 0b1100`, `10 = 0b1010`, result = `0b1000 = 8`. |
|
| 4 | 4 | let a: i32 = 12 & 10; |
|
| 5 | - | if a != 8 { |
|
| 6 | - | return 1; |
|
| 7 | - | } |
|
| 5 | + | assert a == 8; |
|
| 8 | 6 | ||
| 9 | 7 | // Test `|` (bitwise OR). |
|
| 10 | 8 | // `12 = 0b1100`, `10 = 0b1010`, result = `0b1110 = 14`. |
|
| 11 | 9 | let b: i32 = 12 | 10; |
|
| 12 | - | if b != 14 { |
|
| 13 | - | return 2; |
|
| 14 | - | } |
|
| 10 | + | assert b == 14; |
|
| 15 | 11 | ||
| 16 | 12 | // Test `^` (bitwise XOR). |
|
| 17 | 13 | // `12 = 0b1100`, `10 = 0b1010`, result = `0b0110 = 6`. |
|
| 18 | 14 | let c: i32 = 12 ^ 10; |
|
| 19 | - | if c != 6 { |
|
| 20 | - | return 3; |
|
| 21 | - | } |
|
| 15 | + | assert c == 6; |
|
| 22 | 16 | ||
| 23 | 17 | // Test `<<` (shift left). |
|
| 24 | 18 | // `3 << 4 = 48`. |
|
| 25 | 19 | let d: i32 = 3 << 4; |
|
| 26 | - | if d != 48 { |
|
| 27 | - | return 4; |
|
| 28 | - | } |
|
| 20 | + | assert d == 48; |
|
| 29 | 21 | ||
| 30 | 22 | // Test `>>` (shift right, arithmetic for signed). |
|
| 31 | 23 | // `48 >> 2 = 12`. |
|
| 32 | 24 | let e: i32 = 48 >> 2; |
|
| 33 | - | if e != 12 { |
|
| 34 | - | return 5; |
|
| 35 | - | } |
|
| 25 | + | assert e == 12; |
|
| 36 | 26 | ||
| 37 | 27 | // Test `>>` with negative (arithmetic shift preserves sign). |
|
| 38 | 28 | // `-16 >> 2 = -4` (sign bit extended). |
|
| 39 | 29 | let f: i32 = -16 >> 2; |
|
| 40 | - | if f != -4 { |
|
| 41 | - | return 6; |
|
| 42 | - | } |
|
| 30 | + | assert f == -4; |
|
| 43 | 31 | ||
| 44 | 32 | // Test `~` (bitwise NOT). |
|
| 45 | 33 | // `~0 = -1` (all bits set). |
|
| 46 | 34 | let g: i32 = ~0; |
|
| 47 | - | if g != -1 { |
|
| 48 | - | return 7; |
|
| 49 | - | } |
|
| 35 | + | assert g == -1; |
|
| 50 | 36 | ||
| 51 | 37 | // Test `~` with positive value. |
|
| 52 | 38 | // `~1 = -2` (in two's complement). |
|
| 53 | 39 | let h: i32 = ~1; |
|
| 54 | - | if h != -2 { |
|
| 55 | - | return 8; |
|
| 56 | - | } |
|
| 40 | + | assert h == -2; |
|
| 57 | 41 | ||
| 58 | 42 | // Combined operations. |
|
| 59 | 43 | // `(5 | 3) & 6 = 7 & 6 = 6`. |
|
| 60 | 44 | let i: i32 = (5 | 3) & 6; |
|
| 61 | - | if i != 6 { |
|
| 62 | - | return 9; |
|
| 63 | - | } |
|
| 45 | + | assert i == 6; |
|
| 64 | 46 | ||
| 65 | 47 | // XOR self is `0`. |
|
| 66 | 48 | let j: i32 = 42; |
|
| 67 | - | if (j ^ j) != 0 { |
|
| 68 | - | return 10; |
|
| 69 | - | } |
|
| 49 | + | assert (j ^ j) == 0; |
|
| 70 | 50 | return 0; |
|
| 71 | 51 | } |
lib/std/arch/rv64/tests/binop.cmp.rad
+16 -48
| 1 | 1 | @default fn main() -> i32 { |
|
| 2 | 2 | let a: i32 = 5; |
|
| 3 | 3 | let b: i32 = 5; |
|
| 4 | 4 | let c: i32 = 6; |
|
| 5 | 5 | ||
| 6 | - | if not (a == b) { |
|
| 7 | - | return 1; |
|
| 8 | - | } |
|
| 9 | - | if a == c { |
|
| 10 | - | return 2; |
|
| 11 | - | } |
|
| 6 | + | assert (a == b); |
|
| 7 | + | assert a != c; |
|
| 12 | 8 | ||
| 13 | - | if a != b { |
|
| 14 | - | return 3; |
|
| 15 | - | } |
|
| 16 | - | if not (a != c) { |
|
| 17 | - | return 4; |
|
| 18 | - | } |
|
| 9 | + | assert a == b; |
|
| 10 | + | assert (a != c); |
|
| 19 | 11 | ||
| 20 | - | if not (a < c) { |
|
| 21 | - | return 5; |
|
| 22 | - | } |
|
| 23 | - | if a < b { |
|
| 24 | - | return 6; |
|
| 25 | - | } |
|
| 26 | - | if c < a { |
|
| 27 | - | return 7; |
|
| 28 | - | } |
|
| 12 | + | assert (a < c); |
|
| 13 | + | assert a >= b; |
|
| 14 | + | assert c >= a; |
|
| 29 | 15 | ||
| 30 | - | if not (c > a) { |
|
| 31 | - | return 8; |
|
| 32 | - | } |
|
| 33 | - | if a > b { |
|
| 34 | - | return 9; |
|
| 35 | - | } |
|
| 36 | - | if a > c { |
|
| 37 | - | return 10; |
|
| 38 | - | } |
|
| 16 | + | assert (c > a); |
|
| 17 | + | assert a <= b; |
|
| 18 | + | assert a <= c; |
|
| 39 | 19 | ||
| 40 | - | if not (a <= b) { |
|
| 41 | - | return 11; |
|
| 42 | - | } |
|
| 43 | - | if not (a <= c) { |
|
| 44 | - | return 12; |
|
| 45 | - | } |
|
| 46 | - | if c <= a { |
|
| 47 | - | return 13; |
|
| 48 | - | } |
|
| 20 | + | assert (a <= b); |
|
| 21 | + | assert (a <= c); |
|
| 22 | + | assert c > a; |
|
| 49 | 23 | ||
| 50 | - | if not (a >= b) { |
|
| 51 | - | return 14; |
|
| 52 | - | } |
|
| 53 | - | if not (c >= a) { |
|
| 54 | - | return 15; |
|
| 55 | - | } |
|
| 56 | - | if a >= c { |
|
| 57 | - | return 16; |
|
| 58 | - | } |
|
| 24 | + | assert (a >= b); |
|
| 25 | + | assert (c >= a); |
|
| 26 | + | assert a < c; |
|
| 59 | 27 | return 0; |
|
| 60 | 28 | } |
lib/std/arch/rv64/tests/bool.comparison.nested.gen.rad
+3 -9
| 45 | 45 | }; |
|
| 46 | 46 | return c1 != c2; |
|
| 47 | 47 | } |
|
| 48 | 48 | ||
| 49 | 49 | @default fn main() -> i32 { |
|
| 50 | - | if not testNestedEqual() { |
|
| 51 | - | return 1; |
|
| 52 | - | } |
|
| 53 | - | if not testNestedNotEqualCenter() { |
|
| 54 | - | return 2; |
|
| 55 | - | } |
|
| 56 | - | if not testNestedNotEqualRadius() { |
|
| 57 | - | return 3; |
|
| 58 | - | } |
|
| 50 | + | assert testNestedEqual(); |
|
| 51 | + | assert testNestedNotEqualCenter(); |
|
| 52 | + | assert testNestedNotEqualRadius(); |
|
| 59 | 53 | return 0; |
|
| 60 | 54 | } |
lib/std/arch/rv64/tests/bool.comparison.record.gen.rad
+5 -15
| 43 | 43 | ||
| 44 | 44 | return r1 != r2; |
|
| 45 | 45 | } |
|
| 46 | 46 | ||
| 47 | 47 | @default fn main() -> i32 { |
|
| 48 | - | if not testPointEqual() { |
|
| 49 | - | return 1; |
|
| 50 | - | } |
|
| 51 | - | if not testPointNotEqualX() { |
|
| 52 | - | return 2; |
|
| 53 | - | } |
|
| 54 | - | if not testPointNotEqualY() { |
|
| 55 | - | return 3; |
|
| 56 | - | } |
|
| 57 | - | if not testRectEqual() { |
|
| 58 | - | return 4; |
|
| 59 | - | } |
|
| 60 | - | if not testRectNotEqual() { |
|
| 61 | - | return 5; |
|
| 62 | - | } |
|
| 48 | + | assert testPointEqual(); |
|
| 49 | + | assert testPointNotEqualX(); |
|
| 50 | + | assert testPointNotEqualY(); |
|
| 51 | + | assert testRectEqual(); |
|
| 52 | + | assert testRectNotEqual(); |
|
| 63 | 53 | return 0; |
|
| 64 | 54 | } |
lib/std/arch/rv64/tests/bool.comparison.slice.record.gen.rad
+5 -15
| 65 | 65 | ||
| 66 | 66 | return not lineEqual(line1, line2); |
|
| 67 | 67 | } |
|
| 68 | 68 | ||
| 69 | 69 | @default fn main() -> i32 { |
|
| 70 | - | if not testSliceStructEqual() { |
|
| 71 | - | return 1; |
|
| 72 | - | } |
|
| 73 | - | if not testSliceStructNotEqualContent() { |
|
| 74 | - | return 2; |
|
| 75 | - | } |
|
| 76 | - | if not testSliceStructNotEqualLength() { |
|
| 77 | - | return 3; |
|
| 78 | - | } |
|
| 79 | - | if not testStructWithSliceFieldEqual() { |
|
| 80 | - | return 4; |
|
| 81 | - | } |
|
| 82 | - | if not testStructWithSliceFieldNotEqual() { |
|
| 83 | - | return 5; |
|
| 84 | - | } |
|
| 70 | + | assert testSliceStructEqual(); |
|
| 71 | + | assert testSliceStructNotEqualContent(); |
|
| 72 | + | assert testSliceStructNotEqualLength(); |
|
| 73 | + | assert testStructWithSliceFieldEqual(); |
|
| 74 | + | assert testStructWithSliceFieldNotEqual(); |
|
| 85 | 75 | return 0; |
|
| 86 | 76 | } |
lib/std/arch/rv64/tests/bool.comparison.slice.union.gen.rad
+4 -12
| 94 | 94 | ||
| 95 | 95 | return not shapeEqual(s1, s2); |
|
| 96 | 96 | } |
|
| 97 | 97 | ||
| 98 | 98 | @default fn main() -> i32 { |
|
| 99 | - | if not testEnumSliceEqual() { |
|
| 100 | - | return 1; |
|
| 101 | - | } |
|
| 102 | - | if not testEnumSliceNotEqual() { |
|
| 103 | - | return 2; |
|
| 104 | - | } |
|
| 105 | - | if not testEnumSizesSliceEqual() { |
|
| 106 | - | return 3; |
|
| 107 | - | } |
|
| 108 | - | if not testEnumDifferentVariants() { |
|
| 109 | - | return 4; |
|
| 110 | - | } |
|
| 99 | + | assert testEnumSliceEqual(); |
|
| 100 | + | assert testEnumSliceNotEqual(); |
|
| 101 | + | assert testEnumSizesSliceEqual(); |
|
| 102 | + | assert testEnumDifferentVariants(); |
|
| 111 | 103 | return 0; |
|
| 112 | 104 | } |
lib/std/arch/rv64/tests/bool.comparison.union.ctor.rad
+3 -9
| 22 | 22 | let a: Op = Op::Add; |
|
| 23 | 23 | let s: Op = Op::Sub; |
|
| 24 | 24 | let m: Op = Op::Mul; |
|
| 25 | 25 | ||
| 26 | 26 | // isAdd tests |
|
| 27 | - | if not isAdd(a) { |
|
| 28 | - | return 1; |
|
| 29 | - | } |
|
| 27 | + | assert isAdd(a); |
|
| 30 | 28 | if isAdd(s) { |
|
| 31 | 29 | return 2; |
|
| 32 | 30 | } |
|
| 33 | 31 | if isAdd(m) { |
|
| 34 | 32 | return 3; |
|
| 35 | 33 | } |
|
| 36 | 34 | // isSub tests |
|
| 37 | - | if not isSub(s) { |
|
| 38 | - | return 4; |
|
| 39 | - | } |
|
| 35 | + | assert isSub(s); |
|
| 40 | 36 | if isSub(a) { |
|
| 41 | 37 | return 5; |
|
| 42 | 38 | } |
|
| 43 | 39 | // isMul tests |
|
| 44 | - | if not isMul(m) { |
|
| 45 | - | return 6; |
|
| 46 | - | } |
|
| 40 | + | assert isMul(m); |
|
| 47 | 41 | if isMul(a) { |
|
| 48 | 42 | return 7; |
|
| 49 | 43 | } |
|
| 50 | 44 | return 0; |
|
| 51 | 45 | } |
lib/std/arch/rv64/tests/bool.comparison.union.gen.rad
+6 -18
| 46 | 46 | ||
| 47 | 47 | return a != b; |
|
| 48 | 48 | } |
|
| 49 | 49 | ||
| 50 | 50 | @default fn main() -> i32 { |
|
| 51 | - | if not testSameVariantNoPayload() { |
|
| 52 | - | return 1; |
|
| 53 | - | } |
|
| 54 | - | if not testDifferentVariants() { |
|
| 55 | - | return 2; |
|
| 56 | - | } |
|
| 57 | - | if not testSameVariantSamePayload() { |
|
| 58 | - | return 3; |
|
| 59 | - | } |
|
| 60 | - | if not testSameVariantDifferentPayload() { |
|
| 61 | - | return 4; |
|
| 62 | - | } |
|
| 63 | - | if not testBoolPayloadSame() { |
|
| 64 | - | return 5; |
|
| 65 | - | } |
|
| 66 | - | if not testBoolPayloadDifferent() { |
|
| 67 | - | return 6; |
|
| 68 | - | } |
|
| 51 | + | assert testSameVariantNoPayload(); |
|
| 52 | + | assert testDifferentVariants(); |
|
| 53 | + | assert testSameVariantSamePayload(); |
|
| 54 | + | assert testSameVariantDifferentPayload(); |
|
| 55 | + | assert testBoolPayloadSame(); |
|
| 56 | + | assert testBoolPayloadDifferent(); |
|
| 69 | 57 | return 0; |
|
| 70 | 58 | } |
lib/std/arch/rv64/tests/bool.comparison.union.record.gen.rad
+12 -24
| 14 | 14 | circle(u32), |
|
| 15 | 15 | point(Point), |
|
| 16 | 16 | rect(Size), |
|
| 17 | 17 | } |
|
| 18 | 18 | ||
| 19 | - | fn test_same_variant_primitive() -> bool { |
|
| 19 | + | fn testSameVariantPrimitive() -> bool { |
|
| 20 | 20 | let s1: Shape = Shape::circle(10); |
|
| 21 | 21 | let s2: Shape = Shape::circle(10); |
|
| 22 | 22 | return s1 == s2; |
|
| 23 | 23 | } |
|
| 24 | 24 | ||
| 25 | - | fn test_different_variant() -> bool { |
|
| 25 | + | fn testDifferentVariant() -> bool { |
|
| 26 | 26 | let s1: Shape = Shape::circle(10); |
|
| 27 | 27 | let s2: Shape = Shape::point(Point { x: 5, y: 5 }); |
|
| 28 | 28 | return s1 != s2; |
|
| 29 | 29 | } |
|
| 30 | 30 | ||
| 31 | - | fn test_same_variant_struct_equal() -> bool { |
|
| 31 | + | fn testSameVariantStructEqual() -> bool { |
|
| 32 | 32 | let s1: Shape = Shape::point(Point { x: 10, y: 20 }); |
|
| 33 | 33 | let s2: Shape = Shape::point(Point { x: 10, y: 20 }); |
|
| 34 | 34 | return s1 == s2; |
|
| 35 | 35 | } |
|
| 36 | 36 | ||
| 37 | - | fn test_same_variant_struct_not_equal() -> bool { |
|
| 37 | + | fn testSameVariantStructNotEqual() -> bool { |
|
| 38 | 38 | let s1: Shape = Shape::point(Point { x: 10, y: 20 }); |
|
| 39 | 39 | let s2: Shape = Shape::point(Point { x: 10, y: 25 }); |
|
| 40 | 40 | return s1 != s2; |
|
| 41 | 41 | } |
|
| 42 | 42 | ||
| 43 | - | fn test_rect_variant_equal() -> bool { |
|
| 43 | + | fn testRectVariantEqual() -> bool { |
|
| 44 | 44 | let s1: Shape = Shape::rect(Size { width: 100, height: 50 }); |
|
| 45 | 45 | let s2: Shape = Shape::rect(Size { width: 100, height: 50 }); |
|
| 46 | 46 | return s1 == s2; |
|
| 47 | 47 | } |
|
| 48 | 48 | ||
| 49 | - | fn test_rect_variant_not_equal() -> bool { |
|
| 49 | + | fn testRectVariantNotEqual() -> bool { |
|
| 50 | 50 | let s1: Shape = Shape::rect(Size { width: 100, height: 50 }); |
|
| 51 | 51 | let s2: Shape = Shape::rect(Size { width: 100, height: 60 }); |
|
| 52 | 52 | return s1 != s2; |
|
| 53 | 53 | } |
|
| 54 | 54 | ||
| 55 | 55 | @default fn main() -> i32 { |
|
| 56 | - | if not test_same_variant_primitive() { |
|
| 57 | - | return 1; |
|
| 58 | - | } |
|
| 59 | - | if not test_different_variant() { |
|
| 60 | - | return 2; |
|
| 61 | - | } |
|
| 62 | - | if not test_same_variant_struct_equal() { |
|
| 63 | - | return 3; |
|
| 64 | - | } |
|
| 65 | - | if not test_same_variant_struct_not_equal() { |
|
| 66 | - | return 4; |
|
| 67 | - | } |
|
| 68 | - | if not test_rect_variant_equal() { |
|
| 69 | - | return 5; |
|
| 70 | - | } |
|
| 71 | - | if not test_rect_variant_not_equal() { |
|
| 72 | - | return 6; |
|
| 73 | - | } |
|
| 56 | + | assert testSameVariantPrimitive(); |
|
| 57 | + | assert testDifferentVariant(); |
|
| 58 | + | assert testSameVariantStructEqual(); |
|
| 59 | + | assert testSameVariantStructNotEqual(); |
|
| 60 | + | assert testRectVariantEqual(); |
|
| 61 | + | assert testRectVariantNotEqual(); |
|
| 74 | 62 | return 0; |
|
| 75 | 63 | } |
lib/std/arch/rv64/tests/bool.comparison.union.simple.gen.rad
+2 -6
| 8 | 8 | @default fn main() -> i32 { |
|
| 9 | 9 | let r1: Color = Color::red; |
|
| 10 | 10 | let r2: Color = Color::red; |
|
| 11 | 11 | let g: Color = Color::green; |
|
| 12 | 12 | ||
| 13 | - | if r1 != r2 { |
|
| 14 | - | return 1; |
|
| 15 | - | } |
|
| 16 | - | if r1 == g { |
|
| 17 | - | return 2; |
|
| 18 | - | } |
|
| 13 | + | assert r1 == r2; |
|
| 14 | + | assert r1 != g; |
|
| 19 | 15 | return 0; |
|
| 20 | 16 | } |
lib/std/arch/rv64/tests/bool.short.circuit.rad
+22 -66
| 6 | 6 | ||
| 7 | 7 | @default fn main() -> i32 { |
|
| 8 | 8 | // Test 'and' short-circuits when first operand is false. |
|
| 9 | 9 | let mut x1: i32 = 0; |
|
| 10 | 10 | let r1: bool = modify(&mut x1, false) and modify(&mut x1, true); |
|
| 11 | - | if r1 { |
|
| 12 | - | return 1; |
|
| 13 | - | } |
|
| 14 | - | if x1 != 1 { |
|
| 15 | - | return 2; |
|
| 16 | - | } |
|
| 11 | + | assert not r1; |
|
| 12 | + | assert x1 == 1; |
|
| 17 | 13 | ||
| 18 | 14 | // Test 'and' does not short-circuit when first operand is true. |
|
| 19 | 15 | let mut x2: i32 = 0; |
|
| 20 | 16 | let r2: bool = modify(&mut x2, true) and modify(&mut x2, true); |
|
| 21 | - | if not r2 { |
|
| 22 | - | return 3; |
|
| 23 | - | } |
|
| 24 | - | if x2 != 2 { |
|
| 25 | - | return 4; |
|
| 26 | - | } |
|
| 17 | + | assert r2; |
|
| 18 | + | assert x2 == 2; |
|
| 27 | 19 | ||
| 28 | 20 | // Test 'and' evaluates both when first is true, second is false. |
|
| 29 | 21 | let mut x3: i32 = 0; |
|
| 30 | 22 | let r3: bool = modify(&mut x3, true) and modify(&mut x3, false); |
|
| 31 | - | if r3 { |
|
| 32 | - | return 5; |
|
| 33 | - | } |
|
| 34 | - | if x3 != 2 { |
|
| 35 | - | return 6; |
|
| 36 | - | } |
|
| 23 | + | assert not r3; |
|
| 24 | + | assert x3 == 2; |
|
| 37 | 25 | ||
| 38 | 26 | // Test 'or' short-circuits when first operand is true. |
|
| 39 | 27 | let mut x4: i32 = 0; |
|
| 40 | 28 | let r4: bool = modify(&mut x4, true) or modify(&mut x4, true); |
|
| 41 | - | if x4 != 1 { |
|
| 42 | - | return 7; |
|
| 43 | - | } |
|
| 44 | - | if not r4 { |
|
| 45 | - | return 8; |
|
| 46 | - | } |
|
| 29 | + | assert x4 == 1; |
|
| 30 | + | assert r4; |
|
| 47 | 31 | ||
| 48 | 32 | // Test 'or' does not short-circuit when first operand is false. |
|
| 49 | 33 | let mut x5: i32 = 0; |
|
| 50 | 34 | let r5: bool = modify(&mut x5, false) or modify(&mut x5, true); |
|
| 51 | - | if x5 != 2 { |
|
| 52 | - | return 9; |
|
| 53 | - | } |
|
| 54 | - | if not r5 { |
|
| 55 | - | return 10; |
|
| 56 | - | } |
|
| 35 | + | assert x5 == 2; |
|
| 36 | + | assert r5; |
|
| 57 | 37 | ||
| 58 | 38 | let mut y5: i32 = 0; |
|
| 59 | 39 | let t5: bool = modify(&mut y5, false) or modify(&mut y5, false); |
|
| 60 | - | if y5 != 2 { |
|
| 61 | - | return 11; |
|
| 62 | - | } |
|
| 63 | - | if t5 { |
|
| 64 | - | return 12; |
|
| 65 | - | } |
|
| 40 | + | assert y5 == 2; |
|
| 41 | + | assert not t5; |
|
| 66 | 42 | ||
| 67 | 43 | // Test complex short-circuiting with nested expressions. |
|
| 68 | 44 | let mut a6: i32 = 0; |
|
| 69 | 45 | let r6: bool = |
|
| 70 | 46 | modify(&mut a6, false) and |
|
| 71 | 47 | (modify(&mut a6, true) or modify(&mut a6, false)); |
|
| 72 | - | if r6 { |
|
| 73 | - | return 13; |
|
| 74 | - | } |
|
| 75 | - | if a6 != 1 { |
|
| 76 | - | return 14; |
|
| 77 | - | } |
|
| 48 | + | assert not r6; |
|
| 49 | + | assert a6 == 1; |
|
| 78 | 50 | ||
| 79 | 51 | let mut b6: i32 = 0; |
|
| 80 | 52 | let t6: bool = modify(&mut b6, true) and |
|
| 81 | 53 | (modify(&mut b6, false) or modify(&mut b6, false)); |
|
| 82 | - | if t6 { |
|
| 83 | - | return 15; |
|
| 84 | - | } |
|
| 85 | - | if b6 != 3 { |
|
| 86 | - | return 16; |
|
| 87 | - | } |
|
| 54 | + | assert not t6; |
|
| 55 | + | assert b6 == 3; |
|
| 88 | 56 | ||
| 89 | 57 | // Test nested or short-circuit. |
|
| 90 | 58 | let mut a7: i32 = 0; |
|
| 91 | 59 | let r7: bool = modify(&mut a7, false) or |
|
| 92 | 60 | (modify(&mut a7, true) and modify(&mut a7, true)); |
|
| 93 | - | if not r7 { |
|
| 94 | - | return 17; |
|
| 95 | - | } |
|
| 96 | - | if a7 != 3 { |
|
| 97 | - | return 18; |
|
| 98 | - | } |
|
| 61 | + | assert r7; |
|
| 62 | + | assert a7 == 3; |
|
| 99 | 63 | ||
| 100 | 64 | // Test chained 'and' short-circuit. |
|
| 101 | 65 | let mut a8: i32 = 0; |
|
| 102 | 66 | let mut r8: bool = |
|
| 103 | 67 | modify(&mut a8, true) and |
|
| 104 | 68 | modify(&mut a8, false) and |
|
| 105 | 69 | modify(&mut a8, false); |
|
| 106 | - | if r8 { |
|
| 107 | - | return 19; |
|
| 108 | - | } |
|
| 109 | - | if a8 != 2 { |
|
| 110 | - | return 20; |
|
| 111 | - | } |
|
| 70 | + | assert not r8; |
|
| 71 | + | assert a8 == 2; |
|
| 112 | 72 | ||
| 113 | 73 | // Test chained 'or' short-circuit. |
|
| 114 | 74 | let mut a9: i32 = 0; |
|
| 115 | 75 | let mut r9: bool = |
|
| 116 | 76 | modify(&mut a9, false) or |
|
| 117 | 77 | modify(&mut a9, true) or |
|
| 118 | 78 | modify(&mut a9, false); |
|
| 119 | - | if not r9 { |
|
| 120 | - | return 21; |
|
| 121 | - | } |
|
| 122 | - | if a9 != 2 { |
|
| 123 | - | return 22; |
|
| 124 | - | } |
|
| 79 | + | assert r9; |
|
| 80 | + | assert a9 == 2; |
|
| 125 | 81 | ||
| 126 | 82 | return 0; |
|
| 127 | 83 | } |
lib/std/arch/rv64/tests/bool.values.rad
+11 -33
| 4 | 4 | let t: bool = true; |
|
| 5 | 5 | let f: bool = false; |
|
| 6 | 6 | ||
| 7 | 7 | // Assign `and` results to variables. |
|
| 8 | 8 | let a: bool = t and t; |
|
| 9 | - | if not a { |
|
| 10 | - | return 1; |
|
| 11 | - | } |
|
| 9 | + | assert a; |
|
| 12 | 10 | ||
| 13 | 11 | let b: bool = t and f; |
|
| 14 | - | if b { |
|
| 15 | - | return 2; |
|
| 16 | - | } |
|
| 12 | + | assert not b; |
|
| 17 | 13 | ||
| 18 | 14 | let c: bool = f and t; |
|
| 19 | - | if c { |
|
| 20 | - | return 3; |
|
| 21 | - | } |
|
| 15 | + | assert not c; |
|
| 22 | 16 | ||
| 23 | 17 | let d: bool = f and f; |
|
| 24 | - | if d { |
|
| 25 | - | return 4; |
|
| 26 | - | } |
|
| 18 | + | assert not d; |
|
| 27 | 19 | ||
| 28 | 20 | // Assign `or` results to variables. |
|
| 29 | 21 | let e: bool = t or f; |
|
| 30 | - | if not e { |
|
| 31 | - | return 5; |
|
| 32 | - | } |
|
| 22 | + | assert e; |
|
| 33 | 23 | ||
| 34 | 24 | let g: bool = f or t; |
|
| 35 | - | if not g { |
|
| 36 | - | return 6; |
|
| 37 | - | } |
|
| 25 | + | assert g; |
|
| 38 | 26 | ||
| 39 | 27 | let h: bool = t or t; |
|
| 40 | - | if not h { |
|
| 41 | - | return 7; |
|
| 42 | - | } |
|
| 28 | + | assert h; |
|
| 43 | 29 | ||
| 44 | 30 | let i: bool = f or f; |
|
| 45 | - | if i { |
|
| 46 | - | return 8; |
|
| 47 | - | } |
|
| 31 | + | assert not i; |
|
| 48 | 32 | ||
| 49 | 33 | // Nested expressions. |
|
| 50 | 34 | let j: bool = (t and t) or f; |
|
| 51 | - | if not j { |
|
| 52 | - | return 9; |
|
| 53 | - | } |
|
| 35 | + | assert j; |
|
| 54 | 36 | ||
| 55 | 37 | let k: bool = f or (t and t); |
|
| 56 | - | if not k { |
|
| 57 | - | return 10; |
|
| 58 | - | } |
|
| 38 | + | assert k; |
|
| 59 | 39 | ||
| 60 | 40 | let l: bool = (t or f) and (f or t); |
|
| 61 | - | if not l { |
|
| 62 | - | return 11; |
|
| 63 | - | } |
|
| 41 | + | assert l; |
|
| 64 | 42 | return 0; |
|
| 65 | 43 | } |
lib/std/arch/rv64/tests/call.arg.clobber.rad
+1 -3
| 20 | 20 | } |
|
| 21 | 21 | ||
| 22 | 22 | @default fn main() -> i32 { |
|
| 23 | 23 | let r: i32 = test(10); |
|
| 24 | 24 | // Expected: 11+12+13+14+15+16 = 81 |
|
| 25 | - | if r != 81 { |
|
| 26 | - | return 1; |
|
| 27 | - | } |
|
| 25 | + | assert r == 81; |
|
| 28 | 26 | return 0; |
|
| 29 | 27 | } |
lib/std/arch/rv64/tests/call.clobber.rad
+4 -12
| 5 | 5 | } |
|
| 6 | 6 | ||
| 7 | 7 | @default fn main() -> i32 { |
|
| 8 | 8 | let mut x: i32 = 0; |
|
| 9 | 9 | let r: bool = modify(&mut x, false); |
|
| 10 | - | if x != 1 { |
|
| 11 | - | return 1; |
|
| 12 | - | } |
|
| 13 | - | if r { |
|
| 14 | - | return 2; |
|
| 15 | - | } |
|
| 10 | + | assert x == 1; |
|
| 11 | + | assert not r; |
|
| 16 | 12 | ||
| 17 | 13 | // Pointer live across call. |
|
| 18 | 14 | let mut y: i32 = 42; |
|
| 19 | 15 | let p: *mut i32 = &mut y; |
|
| 20 | 16 | let r2: bool = modify(p, true); |
|
| 21 | - | if *p != 43 { |
|
| 22 | - | return 3; |
|
| 23 | - | } |
|
| 24 | - | if not r2 { |
|
| 25 | - | return 4; |
|
| 26 | - | } |
|
| 17 | + | assert *p == 43; |
|
| 18 | + | assert r2; |
|
| 27 | 19 | return 0; |
|
| 28 | 20 | } |
lib/std/arch/rv64/tests/cast.same.size.rad
+10 -30
| 1 | 1 | @default fn main() -> i32 { |
|
| 2 | 2 | // Test i8 -> u8 cast: -1 should become 255. |
|
| 3 | 3 | let x: i8 = -1; |
|
| 4 | 4 | let a: u8 = x as u8; |
|
| 5 | - | if a != 255 { |
|
| 6 | - | return 1; |
|
| 7 | - | } |
|
| 5 | + | assert a == 255; |
|
| 8 | 6 | ||
| 9 | 7 | // Test u8 -> i8 cast: 255 should become -1. |
|
| 10 | 8 | let y: u8 = 255; |
|
| 11 | 9 | let b: i8 = y as i8; |
|
| 12 | - | if b != -1 { |
|
| 13 | - | return 2; |
|
| 14 | - | } |
|
| 10 | + | assert b == -1; |
|
| 15 | 11 | ||
| 16 | 12 | // Test i8 -> u8 with boundary value: -128 should become 128. |
|
| 17 | 13 | let z: i8 = -128; |
|
| 18 | 14 | let c: u8 = z as u8; |
|
| 19 | - | if c != 128 { |
|
| 20 | - | return 3; |
|
| 21 | - | } |
|
| 15 | + | assert c == 128; |
|
| 22 | 16 | ||
| 23 | 17 | // Test u8 -> i8 with boundary value: 128 should become -128. |
|
| 24 | 18 | let w: u8 = 128; |
|
| 25 | 19 | let d: i8 = w as i8; |
|
| 26 | - | if d != -128 { |
|
| 27 | - | return 4; |
|
| 28 | - | } |
|
| 20 | + | assert d == -128; |
|
| 29 | 21 | ||
| 30 | 22 | // Test i16 -> u16 cast: -1 should become 65535. |
|
| 31 | 23 | let p: i16 = -1; |
|
| 32 | 24 | let q: u16 = p as u16; |
|
| 33 | - | if q != 65535 { |
|
| 34 | - | return 5; |
|
| 35 | - | } |
|
| 25 | + | assert q == 65535; |
|
| 36 | 26 | ||
| 37 | 27 | // Test u16 -> i16 cast: 65535 should become -1. |
|
| 38 | 28 | let r: u16 = 65535; |
|
| 39 | 29 | let s: i16 = r as i16; |
|
| 40 | - | if s != -1 { |
|
| 41 | - | return 6; |
|
| 42 | - | } |
|
| 30 | + | assert s == -1; |
|
| 43 | 31 | ||
| 44 | 32 | // Eq/Ne used as values must compare at the declared width. |
|
| 45 | 33 | let eqU8: bool = a == 255; |
|
| 46 | - | if not eqU8 { |
|
| 47 | - | return 7; |
|
| 48 | - | } |
|
| 34 | + | assert eqU8; |
|
| 49 | 35 | let eqI8: bool = b == -1; |
|
| 50 | - | if not eqI8 { |
|
| 51 | - | return 8; |
|
| 52 | - | } |
|
| 36 | + | assert eqI8; |
|
| 53 | 37 | let neU8: bool = a != 255; |
|
| 54 | - | if neU8 { |
|
| 55 | - | return 9; |
|
| 56 | - | } |
|
| 38 | + | assert not neU8; |
|
| 57 | 39 | let neI8: bool = b != -1; |
|
| 58 | - | if neI8 { |
|
| 59 | - | return 10; |
|
| 60 | - | } |
|
| 40 | + | assert not neI8; |
|
| 61 | 41 | return 0; |
|
| 62 | 42 | } |
lib/std/arch/rv64/tests/casting.numbers.rad
+8 -24
| 66 | 66 | ||
| 67 | 67 | return y == -2147483648 and z == 2147483648; |
|
| 68 | 68 | } |
|
| 69 | 69 | ||
| 70 | 70 | @default fn main() -> i32 { |
|
| 71 | - | if not casting() { |
|
| 72 | - | return 1; |
|
| 73 | - | } |
|
| 74 | - | if not zeroExtension() { |
|
| 75 | - | return 2; |
|
| 76 | - | } |
|
| 77 | - | if not signedCasting() { |
|
| 78 | - | return 3; |
|
| 79 | - | } |
|
| 80 | - | if not unsignedToSigned() { |
|
| 81 | - | return 4; |
|
| 82 | - | } |
|
| 83 | - | if not signed16bitCasting() { |
|
| 84 | - | return 5; |
|
| 85 | - | } |
|
| 86 | - | if not maxU8Casting() { |
|
| 87 | - | return 6; |
|
| 88 | - | } |
|
| 89 | - | if not truncationTest() { |
|
| 90 | - | return 7; |
|
| 91 | - | } |
|
| 92 | - | if not sameSizeCasting() { |
|
| 93 | - | return 8; |
|
| 94 | - | } |
|
| 71 | + | assert casting(); |
|
| 72 | + | assert zeroExtension(); |
|
| 73 | + | assert signedCasting(); |
|
| 74 | + | assert unsignedToSigned(); |
|
| 75 | + | assert signed16bitCasting(); |
|
| 76 | + | assert maxU8Casting(); |
|
| 77 | + | assert truncationTest(); |
|
| 78 | + | assert sameSizeCasting(); |
|
| 95 | 79 | return 0; |
|
| 96 | 80 | } |
lib/std/arch/rv64/tests/char.literal.rad
+3 -9
| 1 | 1 | //! Test character literals including escaped chars. |
|
| 2 | 2 | @default fn main() -> i32 { |
|
| 3 | - | if 'a' != 97 { |
|
| 4 | - | return 1; |
|
| 5 | - | } |
|
| 6 | - | if '\'' != 39 { |
|
| 7 | - | return 2; |
|
| 8 | - | } |
|
| 9 | - | if '\\' != 92 { |
|
| 10 | - | return 3; |
|
| 11 | - | } |
|
| 3 | + | assert 'a' == 97; |
|
| 4 | + | assert '\'' == 39; |
|
| 5 | + | assert '\\' == 92; |
|
| 12 | 6 | return 0; |
|
| 13 | 7 | } |
lib/std/arch/rv64/tests/compound.assign.field.rad
+3 -9
| 6 | 6 | ||
| 7 | 7 | @default fn main() -> i32 { |
|
| 8 | 8 | let mut p = Point { x: 10, y: 20 }; |
|
| 9 | 9 | ||
| 10 | 10 | p.x += 5; |
|
| 11 | - | if p.x != 15 { |
|
| 12 | - | return 1; |
|
| 13 | - | } |
|
| 11 | + | assert p.x == 15; |
|
| 14 | 12 | ||
| 15 | 13 | p.y -= 3; |
|
| 16 | - | if p.y != 17 { |
|
| 17 | - | return 2; |
|
| 18 | - | } |
|
| 14 | + | assert p.y == 17; |
|
| 19 | 15 | ||
| 20 | 16 | p.x *= 2; |
|
| 21 | - | if p.x != 30 { |
|
| 22 | - | return 3; |
|
| 23 | - | } |
|
| 17 | + | assert p.x == 30; |
|
| 24 | 18 | ||
| 25 | 19 | return 0; |
|
| 26 | 20 | } |
lib/std/arch/rv64/tests/compound.assign.rad
+13 -39
| 2 | 2 | @default fn main() -> i32 { |
|
| 3 | 3 | let mut a: i32 = 10; |
|
| 4 | 4 | ||
| 5 | 5 | // Test += |
|
| 6 | 6 | a += 5; |
|
| 7 | - | if a != 15 { |
|
| 8 | - | return 1; |
|
| 9 | - | } |
|
| 7 | + | assert a == 15; |
|
| 10 | 8 | ||
| 11 | 9 | // Test -= |
|
| 12 | 10 | a -= 3; |
|
| 13 | - | if a != 12 { |
|
| 14 | - | return 2; |
|
| 15 | - | } |
|
| 11 | + | assert a == 12; |
|
| 16 | 12 | ||
| 17 | 13 | // Test *= |
|
| 18 | 14 | a *= 2; |
|
| 19 | - | if a != 24 { |
|
| 20 | - | return 3; |
|
| 21 | - | } |
|
| 15 | + | assert a == 24; |
|
| 22 | 16 | ||
| 23 | 17 | // Test /= |
|
| 24 | 18 | a /= 4; |
|
| 25 | - | if a != 6 { |
|
| 26 | - | return 4; |
|
| 27 | - | } |
|
| 19 | + | assert a == 6; |
|
| 28 | 20 | ||
| 29 | 21 | // Test %= |
|
| 30 | 22 | a %= 4; |
|
| 31 | - | if a != 2 { |
|
| 32 | - | return 5; |
|
| 33 | - | } |
|
| 23 | + | assert a == 2; |
|
| 34 | 24 | ||
| 35 | 25 | // Test &= |
|
| 36 | 26 | let mut b: i32 = 0xFF; |
|
| 37 | 27 | b &= 0x0F; |
|
| 38 | - | if b != 0x0F { |
|
| 39 | - | return 6; |
|
| 40 | - | } |
|
| 28 | + | assert b == 0x0F; |
|
| 41 | 29 | ||
| 42 | 30 | // Test |= |
|
| 43 | 31 | b |= 0xF0; |
|
| 44 | - | if b != 0xFF { |
|
| 45 | - | return 7; |
|
| 46 | - | } |
|
| 32 | + | assert b == 0xFF; |
|
| 47 | 33 | ||
| 48 | 34 | // Test ^= |
|
| 49 | 35 | b ^= 0x0F; |
|
| 50 | - | if b != 0xF0 { |
|
| 51 | - | return 8; |
|
| 52 | - | } |
|
| 36 | + | assert b == 0xF0; |
|
| 53 | 37 | ||
| 54 | 38 | // Test <<= |
|
| 55 | 39 | let mut c: i32 = 1; |
|
| 56 | 40 | c <<= 4; |
|
| 57 | - | if c != 16 { |
|
| 58 | - | return 9; |
|
| 59 | - | } |
|
| 41 | + | assert c == 16; |
|
| 60 | 42 | ||
| 61 | 43 | // Test >>= |
|
| 62 | 44 | c >>= 2; |
|
| 63 | - | if c != 4 { |
|
| 64 | - | return 10; |
|
| 65 | - | } |
|
| 45 | + | assert c == 4; |
|
| 66 | 46 | ||
| 67 | 47 | // Test compound assignment with array subscript. |
|
| 68 | 48 | let mut arr: [i32; 3] = [10, 20, 30]; |
|
| 69 | 49 | arr[1] += 5; |
|
| 70 | - | if arr[1] != 25 { |
|
| 71 | - | return 11; |
|
| 72 | - | } |
|
| 50 | + | assert arr[1] == 25; |
|
| 73 | 51 | ||
| 74 | 52 | // Test compound assignment with pointer dereference. |
|
| 75 | 53 | let mut val: i32 = 100; |
|
| 76 | 54 | let p: *mut i32 = &mut val; |
|
| 77 | 55 | *p += 50; |
|
| 78 | - | if val != 150 { |
|
| 79 | - | return 12; |
|
| 80 | - | } |
|
| 56 | + | assert val == 150; |
|
| 81 | 57 | ||
| 82 | 58 | // Test chained compound assignments. |
|
| 83 | 59 | let mut x: i32 = 1; |
|
| 84 | 60 | x += 2; |
|
| 85 | 61 | x *= 3; |
|
| 86 | 62 | x -= 1; |
|
| 87 | - | if x != 8 { |
|
| 88 | - | return 13; |
|
| 89 | - | } |
|
| 63 | + | assert x == 8; |
|
| 90 | 64 | ||
| 91 | 65 | return 0; |
|
| 92 | 66 | } |
lib/std/arch/rv64/tests/cond.assign.rad
+3 -9
| 9 | 9 | if t { |
|
| 10 | 10 | x = 1; |
|
| 11 | 11 | } else { |
|
| 12 | 12 | x = 2; |
|
| 13 | 13 | } |
|
| 14 | - | if x != 1 { |
|
| 15 | - | return 1; |
|
| 16 | - | } |
|
| 14 | + | assert x == 1; |
|
| 17 | 15 | ||
| 18 | 16 | // `if-else` with `false` condition. |
|
| 19 | 17 | let f: bool = false; |
|
| 20 | 18 | if f { |
|
| 21 | 19 | x = 10; |
|
| 22 | 20 | } else { |
|
| 23 | 21 | x = 20; |
|
| 24 | 22 | } |
|
| 25 | - | if x != 20 { |
|
| 26 | - | return 2; |
|
| 27 | - | } |
|
| 23 | + | assert x == 20; |
|
| 28 | 24 | ||
| 29 | 25 | // `if-else` chain. |
|
| 30 | 26 | let a: i32 = 5; |
|
| 31 | 27 | if a == 3 { |
|
| 32 | 28 | x = 100; |
|
| 33 | 29 | } else if a == 5 { |
|
| 34 | 30 | x = 200; |
|
| 35 | 31 | } else { |
|
| 36 | 32 | x = 300; |
|
| 37 | 33 | } |
|
| 38 | - | if x != 200 { |
|
| 39 | - | return 3; |
|
| 40 | - | } |
|
| 34 | + | assert x == 200; |
|
| 41 | 35 | return 0; |
|
| 42 | 36 | } |
lib/std/arch/rv64/tests/cond.expr.aggregate.rad
+4 -12
| 15 | 15 | ||
| 16 | 16 | /// Test tagged union conditional expression. |
|
| 17 | 17 | fn testUnion() -> i32 { |
|
| 18 | 18 | let v1 = pickVal(true, 7); |
|
| 19 | 19 | if let case Val::Reg(r) = v1 { |
|
| 20 | - | if r != 7 { |
|
| 21 | - | return 1; |
|
| 22 | - | } |
|
| 20 | + | assert r == 7; |
|
| 23 | 21 | } else { |
|
| 24 | 22 | return 2; |
|
| 25 | 23 | } |
|
| 26 | 24 | ||
| 27 | 25 | let v2 = pickVal(false, 7); |
|
| 28 | 26 | if let case Val::Imm(i) = v2 { |
|
| 29 | - | if i != 99 { |
|
| 30 | - | return 3; |
|
| 31 | - | } |
|
| 27 | + | assert i == 99; |
|
| 32 | 28 | } else { |
|
| 33 | 29 | return 4; |
|
| 34 | 30 | } |
|
| 35 | 31 | return 0; |
|
| 36 | 32 | } |
| 43 | 39 | ||
| 44 | 40 | let r1 = pickOpt(a, b); |
|
| 45 | 41 | let v1 = r1 else { |
|
| 46 | 42 | return 10; |
|
| 47 | 43 | }; |
|
| 48 | - | if v1 != 42 { |
|
| 49 | - | return 11; |
|
| 50 | - | } |
|
| 44 | + | assert v1 == 42; |
|
| 51 | 45 | ||
| 52 | 46 | let r2 = pickOpt(n, b); |
|
| 53 | 47 | let v2 = r2 else { |
|
| 54 | 48 | return 12; |
|
| 55 | 49 | }; |
|
| 56 | - | if v2 != 99 { |
|
| 57 | - | return 13; |
|
| 58 | - | } |
|
| 50 | + | assert v2 == 99; |
|
| 59 | 51 | ||
| 60 | 52 | return 0; |
|
| 61 | 53 | } |
|
| 62 | 54 | ||
| 63 | 55 | @default fn main() -> i32 { |
lib/std/arch/rv64/tests/cond.expr.rad
+11 -33
| 15 | 15 | } |
|
| 16 | 16 | ||
| 17 | 17 | /// Test basic scalar conditional expression. |
|
| 18 | 18 | fn testScalar() -> i32 { |
|
| 19 | 19 | let x: i32 = 10 if true else 20; |
|
| 20 | - | if x != 10 { |
|
| 21 | - | return 1; |
|
| 22 | - | } |
|
| 20 | + | assert x == 10; |
|
| 23 | 21 | let y: i32 = 10 if false else 20; |
|
| 24 | - | if y != 20 { |
|
| 25 | - | return 2; |
|
| 26 | - | } |
|
| 22 | + | assert y == 20; |
|
| 27 | 23 | return 0; |
|
| 28 | 24 | } |
|
| 29 | 25 | ||
| 30 | 26 | /// Test min-value pattern. |
|
| 31 | 27 | fn testMin() -> i32 { |
|
| 32 | - | if min(5, 3) != 3 { |
|
| 33 | - | return 10; |
|
| 34 | - | } |
|
| 35 | - | if min(3, 5) != 3 { |
|
| 36 | - | return 11; |
|
| 37 | - | } |
|
| 38 | - | if min(4, 4) != 4 { |
|
| 39 | - | return 12; |
|
| 40 | - | } |
|
| 28 | + | assert min(5, 3) == 3; |
|
| 29 | + | assert min(3, 5) == 3; |
|
| 30 | + | assert min(4, 4) == 4; |
|
| 41 | 31 | return 0; |
|
| 42 | 32 | } |
|
| 43 | 33 | ||
| 44 | 34 | /// Test with function argument as condition. |
|
| 45 | 35 | fn testFnArg() -> i32 { |
|
| 46 | - | if pick(true, 42, 99) != 42 { |
|
| 47 | - | return 20; |
|
| 48 | - | } |
|
| 49 | - | if pick(false, 42, 99) != 99 { |
|
| 50 | - | return 21; |
|
| 51 | - | } |
|
| 36 | + | assert pick(true, 42, 99) == 42; |
|
| 37 | + | assert pick(false, 42, 99) == 99; |
|
| 52 | 38 | return 0; |
|
| 53 | 39 | } |
|
| 54 | 40 | ||
| 55 | 41 | /// Test with enum values. |
|
| 56 | 42 | fn testEnum() -> i32 { |
|
| 57 | 43 | let c1 = colorPick(true); |
|
| 58 | - | if c1 != Color::Red { |
|
| 59 | - | return 30; |
|
| 60 | - | } |
|
| 44 | + | assert c1 == Color::Red; |
|
| 61 | 45 | let c2 = colorPick(false); |
|
| 62 | - | if c2 != Color::Blue { |
|
| 63 | - | return 31; |
|
| 64 | - | } |
|
| 46 | + | assert c2 == Color::Blue; |
|
| 65 | 47 | return 0; |
|
| 66 | 48 | } |
|
| 67 | 49 | ||
| 68 | 50 | /// Test nested conditional expression (right-associative). |
|
| 69 | 51 | fn testNested() -> i32 { |
| 71 | 53 | let b: i32 = 1; |
|
| 72 | 54 | let c: i32 = 2; |
|
| 73 | 55 | ||
| 74 | 56 | // a if false else b if false else c => a if false else (b if false else c) => c |
|
| 75 | 57 | let result: i32 = a if false else b if false else c; |
|
| 76 | - | if result != 2 { |
|
| 77 | - | return 40; |
|
| 78 | - | } |
|
| 58 | + | assert result == 2; |
|
| 79 | 59 | ||
| 80 | 60 | // a if true else b if false else c => a |
|
| 81 | 61 | let result2: i32 = a if true else b if false else c; |
|
| 82 | - | if result2 != 0 { |
|
| 83 | - | return 41; |
|
| 84 | - | } |
|
| 62 | + | assert result2 == 0; |
|
| 85 | 63 | return 0; |
|
| 86 | 64 | } |
|
| 87 | 65 | ||
| 88 | 66 | @default fn main() -> i32 { |
|
| 89 | 67 | let r1 = testScalar(); |
lib/std/arch/rv64/tests/cond.for.unsigned.range.rad
+3 -9
| 5 | 5 | let mut count: i32 = 0; |
|
| 6 | 6 | ||
| 7 | 7 | for i in start..end { |
|
| 8 | 8 | count += 1; |
|
| 9 | 9 | } |
|
| 10 | - | if count != 1 { |
|
| 11 | - | return 1; |
|
| 12 | - | } |
|
| 10 | + | assert count == 1; |
|
| 13 | 11 | ||
| 14 | 12 | // Unsigned range above signed boundary. |
|
| 15 | 13 | let start2: u32 = 2147483648; |
|
| 16 | 14 | let end2: u32 = 2147483651; |
|
| 17 | 15 | let mut count2: i32 = 0; |
|
| 18 | 16 | ||
| 19 | 17 | for i in start2..end2 { |
|
| 20 | 18 | count2 += 1; |
|
| 21 | 19 | } |
|
| 22 | - | if count2 != 3 { |
|
| 23 | - | return 2; |
|
| 24 | - | } |
|
| 20 | + | assert count2 == 3; |
|
| 25 | 21 | ||
| 26 | 22 | // Signed range still uses signed ordering. |
|
| 27 | 23 | let mut sum: i32 = 0; |
|
| 28 | 24 | for i in -2..2 { |
|
| 29 | 25 | sum += i; |
|
| 30 | 26 | } |
|
| 31 | - | if sum != -2 { |
|
| 32 | - | return 3; |
|
| 33 | - | } |
|
| 27 | + | assert sum == -2; |
|
| 34 | 28 | ||
| 35 | 29 | return 0; |
|
| 36 | 30 | } |
lib/std/arch/rv64/tests/cond.if.rad
+4 -12
| 7 | 7 | return 1; |
|
| 8 | 8 | } |
|
| 9 | 9 | ||
| 10 | 10 | // Basic `if` with `false`. |
|
| 11 | 11 | let f: bool = false; |
|
| 12 | - | if f { |
|
| 13 | - | return 2; |
|
| 14 | - | } |
|
| 12 | + | assert not f; |
|
| 15 | 13 | ||
| 16 | 14 | // Boolean `not`. |
|
| 17 | 15 | if not f { |
|
| 18 | 16 | } else { |
|
| 19 | 17 | return 3; |
|
| 20 | 18 | } |
|
| 21 | - | if not t { |
|
| 22 | - | return 4; |
|
| 23 | - | } |
|
| 19 | + | assert t; |
|
| 24 | 20 | ||
| 25 | 21 | // Comparison in condition. |
|
| 26 | 22 | let a: i32 = 5; |
|
| 27 | 23 | let b: i32 = 10; |
|
| 28 | 24 | if a < b { |
|
| 29 | 25 | // Ignore. |
|
| 30 | 26 | } else { |
|
| 31 | 27 | return 5; |
|
| 32 | 28 | } |
|
| 33 | - | if a > b { |
|
| 34 | - | return 6; |
|
| 35 | - | } |
|
| 29 | + | assert a <= b; |
|
| 36 | 30 | if a == a { |
|
| 37 | 31 | // Ignore. |
|
| 38 | 32 | } else { |
|
| 39 | 33 | return 7; |
|
| 40 | 34 | } |
| 44 | 38 | return 8; |
|
| 45 | 39 | } |
|
| 46 | 40 | ||
| 47 | 41 | // Nested if. |
|
| 48 | 42 | if t { |
|
| 49 | - | if f { |
|
| 50 | - | return 9; |
|
| 51 | - | } |
|
| 43 | + | assert not f; |
|
| 52 | 44 | } |
|
| 53 | 45 | ||
| 54 | 46 | // `if` in `else` branch. |
|
| 55 | 47 | if f { |
|
| 56 | 48 | return 10; |
lib/std/arch/rv64/tests/cond.match.guard.rad
+10 -30
| 40 | 40 | } |
|
| 41 | 41 | } |
|
| 42 | 42 | } |
|
| 43 | 43 | ||
| 44 | 44 | @default fn main() -> i32 { |
|
| 45 | - | if checkStmt(OptionNum::Some(5)) != 5 { |
|
| 46 | - | return 1; |
|
| 47 | - | } |
|
| 48 | - | if checkStmt(OptionNum::Some(2)) != -2 { |
|
| 49 | - | return 2; |
|
| 50 | - | } |
|
| 51 | - | if checkStmt(OptionNum::Other(7)) != 14 { |
|
| 52 | - | return 3; |
|
| 53 | - | } |
|
| 54 | - | if checkStmt(OptionNum::Other(3)) != 0 { |
|
| 55 | - | return 4; |
|
| 56 | - | } |
|
| 57 | - | if checkStmt(OptionNum::None) != 0 { |
|
| 58 | - | return 5; |
|
| 59 | - | } |
|
| 60 | - | if checkExpr(OptionNum::Some(5)) != 6 { |
|
| 61 | - | return 6; |
|
| 62 | - | } |
|
| 63 | - | if checkExpr(OptionNum::Some(9)) != 11 { |
|
| 64 | - | return 7; |
|
| 65 | - | } |
|
| 66 | - | if checkExpr(OptionNum::Other(7)) != 10 { |
|
| 67 | - | return 8; |
|
| 68 | - | } |
|
| 69 | - | if checkExpr(OptionNum::Other(3)) != 0 { |
|
| 70 | - | return 9; |
|
| 71 | - | } |
|
| 72 | - | if checkExpr(OptionNum::None) != 0 { |
|
| 73 | - | return 10; |
|
| 74 | - | } |
|
| 45 | + | assert checkStmt(OptionNum::Some(5)) == 5; |
|
| 46 | + | assert checkStmt(OptionNum::Some(2)) == -2; |
|
| 47 | + | assert checkStmt(OptionNum::Other(7)) == 14; |
|
| 48 | + | assert checkStmt(OptionNum::Other(3)) == 0; |
|
| 49 | + | assert checkStmt(OptionNum::None) == 0; |
|
| 50 | + | assert checkExpr(OptionNum::Some(5)) == 6; |
|
| 51 | + | assert checkExpr(OptionNum::Some(9)) == 11; |
|
| 52 | + | assert checkExpr(OptionNum::Other(7)) == 10; |
|
| 53 | + | assert checkExpr(OptionNum::Other(3)) == 0; |
|
| 54 | + | assert checkExpr(OptionNum::None) == 0; |
|
| 75 | 55 | return 0; |
|
| 76 | 56 | } |
lib/std/arch/rv64/tests/cond.match.guard.regalloc.rad
+4 -12
| 42 | 42 | }; |
|
| 43 | 43 | let mut buffer: [*[u8]; 4] = undefined; |
|
| 44 | 44 | let path = getPath(&n, &mut buffer[..]); |
|
| 45 | 45 | ||
| 46 | 46 | let pathLen = path.len as i32; |
|
| 47 | - | if pathLen > 1 { |
|
| 48 | - | return 1; |
|
| 49 | - | } |
|
| 50 | - | if pathLen <= 0 { |
|
| 51 | - | return 2; |
|
| 52 | - | } |
|
| 47 | + | assert pathLen <= 1; |
|
| 48 | + | assert pathLen > 0; |
|
| 53 | 49 | ||
| 54 | 50 | let elemLen = path[0].len as i32; |
|
| 55 | - | if elemLen > 5 { |
|
| 56 | - | return 3; |
|
| 57 | - | } |
|
| 58 | - | if elemLen <= 4 { |
|
| 59 | - | return 4; |
|
| 60 | - | } |
|
| 51 | + | assert elemLen <= 5; |
|
| 52 | + | assert elemLen > 4; |
|
| 61 | 53 | return 0; |
|
| 62 | 54 | } |
lib/std/arch/rv64/tests/const.fn.array.rad
+3 -9
| 18 | 18 | const OPS: [fn(i32, i32) -> i32; 3] = [add, sub, mul]; |
|
| 19 | 19 | ||
| 20 | 20 | @default fn main() -> i32 { |
|
| 21 | 21 | // add(10, 3) == 13 |
|
| 22 | 22 | let r0 = OPS[0](10, 3); |
|
| 23 | - | if r0 != 13 { |
|
| 24 | - | return 1; |
|
| 25 | - | } |
|
| 23 | + | assert r0 == 13; |
|
| 26 | 24 | // sub(10, 3) == 7 |
|
| 27 | 25 | let r1 = OPS[1](10, 3); |
|
| 28 | - | if r1 != 7 { |
|
| 29 | - | return 2; |
|
| 30 | - | } |
|
| 26 | + | assert r1 == 7; |
|
| 31 | 27 | // mul(10, 3) == 30 |
|
| 32 | 28 | let r2 = OPS[2](10, 3); |
|
| 33 | - | if r2 != 30 { |
|
| 34 | - | return 3; |
|
| 35 | - | } |
|
| 29 | + | assert r2 == 30; |
|
| 36 | 30 | return 0; |
|
| 37 | 31 | } |
lib/std/arch/rv64/tests/const.record.ctor.rad
+1 -3
| 2 | 2 | record Pair(i32, i32); |
|
| 3 | 3 | ||
| 4 | 4 | const P: Pair = Pair(40, 2); |
|
| 5 | 5 | ||
| 6 | 6 | @default fn main() -> i32 { |
|
| 7 | - | if P != Pair(40, 2) { |
|
| 8 | - | return 1; |
|
| 9 | - | } |
|
| 7 | + | assert P == Pair(40, 2); |
|
| 10 | 8 | return 0; |
|
| 11 | 9 | } |
lib/std/arch/rv64/tests/const.union.payload.ctor.rad
+1 -3
| 8 | 8 | const V: Value = Value::Int(42); |
|
| 9 | 9 | ||
| 10 | 10 | @default fn main() -> i32 { |
|
| 11 | 11 | match V { |
|
| 12 | 12 | case Value::Int(x) => { |
|
| 13 | - | if x != 42 { |
|
| 14 | - | return 1; |
|
| 15 | - | } |
|
| 13 | + | assert x == 42; |
|
| 16 | 14 | } |
|
| 17 | 15 | case Value::Bool(_) => return 2, |
|
| 18 | 16 | case Value::None => return 3, |
|
| 19 | 17 | } |
|
| 20 | 18 | return 0; |
lib/std/arch/rv64/tests/const.union.record.literal.rad
+1 -3
| 8 | 8 | ||
| 9 | 9 | @default fn main() -> i32 { |
|
| 10 | 10 | match E { |
|
| 11 | 11 | case Expr::Nil => return 1, |
|
| 12 | 12 | case Expr::Pair { first, second } => { |
|
| 13 | - | if first + second != 42 { |
|
| 14 | - | return 2; |
|
| 15 | - | } |
|
| 13 | + | assert first + second == 42; |
|
| 16 | 14 | } |
|
| 17 | 15 | } |
|
| 18 | 16 | return 0; |
|
| 19 | 17 | } |
lib/std/arch/rv64/tests/data.array.rad
+14 -14
| 6 | 6 | const I16S: [i16; 2] = [-1000, 1000]; |
|
| 7 | 7 | const I32S: [i32; 2] = [-100000, 100000]; |
|
| 8 | 8 | const BOOLS: [bool; 2] = [true, false]; |
|
| 9 | 9 | ||
| 10 | 10 | @default fn main() -> i32 { |
|
| 11 | - | if U8S[0] != 10 { return 1; } |
|
| 12 | - | if U8S[1] != 20 { return 2; } |
|
| 11 | + | assert U8S[0] == 10; |
|
| 12 | + | assert U8S[1] == 20; |
|
| 13 | 13 | ||
| 14 | - | if U16S[0] != 1000 { return 3; } |
|
| 15 | - | if U16S[1] != 2000 { return 4; } |
|
| 14 | + | assert U16S[0] == 1000; |
|
| 15 | + | assert U16S[1] == 2000; |
|
| 16 | 16 | ||
| 17 | - | if U32S[0] != 100000 { return 5; } |
|
| 18 | - | if U32S[1] != 200000 { return 6; } |
|
| 17 | + | assert U32S[0] == 100000; |
|
| 18 | + | assert U32S[1] == 200000; |
|
| 19 | 19 | ||
| 20 | - | if I8S[0] != -10 { return 7; } |
|
| 21 | - | if I8S[1] != 10 { return 8; } |
|
| 20 | + | assert I8S[0] == -10; |
|
| 21 | + | assert I8S[1] == 10; |
|
| 22 | 22 | ||
| 23 | - | if I16S[0] != -1000 { return 9; } |
|
| 24 | - | if I16S[1] != 1000 { return 10; } |
|
| 23 | + | assert I16S[0] == -1000; |
|
| 24 | + | assert I16S[1] == 1000; |
|
| 25 | 25 | ||
| 26 | - | if I32S[0] != -100000 { return 11; } |
|
| 27 | - | if I32S[1] != 100000 { return 12; } |
|
| 26 | + | assert I32S[0] == -100000; |
|
| 27 | + | assert I32S[1] == 100000; |
|
| 28 | 28 | ||
| 29 | - | if BOOLS[0] != true { return 13; } |
|
| 30 | - | if BOOLS[1] != false { return 14; } |
|
| 29 | + | assert BOOLS[0] == true; |
|
| 30 | + | assert BOOLS[1] == false; |
|
| 31 | 31 | ||
| 32 | 32 | return 0; |
|
| 33 | 33 | } |
lib/std/arch/rv64/tests/data.bool.rad
+4 -4
| 1 | 1 | //! Test read-only data access for `bool` type. |
|
| 2 | 2 | const T: bool = true; |
|
| 3 | 3 | const F: bool = false; |
|
| 4 | 4 | ||
| 5 | 5 | @default fn main() -> i32 { |
|
| 6 | - | if T != true { return 1; } |
|
| 7 | - | if F != false { return 2; } |
|
| 8 | - | if not T { return 3; } |
|
| 9 | - | if F { return 4; } |
|
| 6 | + | assert T == true; |
|
| 7 | + | assert F == false; |
|
| 8 | + | assert T; |
|
| 9 | + | assert not F; |
|
| 10 | 10 | ||
| 11 | 11 | return 0; |
|
| 12 | 12 | } |
lib/std/arch/rv64/tests/data.i16.rad
+4 -4
| 3 | 3 | const B: i16 = 32767; |
|
| 4 | 4 | const C: i16 = -32768; |
|
| 5 | 5 | const D: i16 = -1; |
|
| 6 | 6 | ||
| 7 | 7 | @default fn main() -> i32 { |
|
| 8 | - | if A != 0 { return 1; } |
|
| 9 | - | if B != 32767 { return 2; } |
|
| 10 | - | if C != -32768 { return 3; } |
|
| 11 | - | if D != -1 { return 4; } |
|
| 8 | + | assert A == 0; |
|
| 9 | + | assert B == 32767; |
|
| 10 | + | assert C == -32768; |
|
| 11 | + | assert D == -1; |
|
| 12 | 12 | ||
| 13 | 13 | return 0; |
|
| 14 | 14 | } |
lib/std/arch/rv64/tests/data.i32.rad
+4 -4
| 3 | 3 | const B: i32 = 2147483647; |
|
| 4 | 4 | const C: i32 = -2147483648; |
|
| 5 | 5 | const D: i32 = -1; |
|
| 6 | 6 | ||
| 7 | 7 | @default fn main() -> i32 { |
|
| 8 | - | if A != 0 { return 1; } |
|
| 9 | - | if B != 2147483647 { return 2; } |
|
| 10 | - | if C != -2147483648 { return 3; } |
|
| 11 | - | if D != -1 { return 4; } |
|
| 8 | + | assert A == 0; |
|
| 9 | + | assert B == 2147483647; |
|
| 10 | + | assert C == -2147483648; |
|
| 11 | + | assert D == -1; |
|
| 12 | 12 | ||
| 13 | 13 | return 0; |
|
| 14 | 14 | } |
lib/std/arch/rv64/tests/data.i8.rad
+4 -4
| 3 | 3 | const B: i8 = 127; |
|
| 4 | 4 | const C: i8 = -128; |
|
| 5 | 5 | const D: i8 = -1; |
|
| 6 | 6 | ||
| 7 | 7 | @default fn main() -> i32 { |
|
| 8 | - | if A != 0 { return 1; } |
|
| 9 | - | if B != 127 { return 2; } |
|
| 10 | - | if C != -128 { return 3; } |
|
| 11 | - | if D != -1 { return 4; } |
|
| 8 | + | assert A == 0; |
|
| 9 | + | assert B == 127; |
|
| 10 | + | assert C == -128; |
|
| 11 | + | assert D == -1; |
|
| 12 | 12 | ||
| 13 | 13 | return 0; |
|
| 14 | 14 | } |
lib/std/arch/rv64/tests/data.record.rad
+8 -8
| 14 | 14 | const ORIGIN: Point = Point { x: 0, y: 0 }; |
|
| 15 | 15 | const P1: Point = Point { x: 100, y: -50 }; |
|
| 16 | 16 | const M1: Mixed = Mixed { a: 255, b: 1000, c: 100000, d: true }; |
|
| 17 | 17 | ||
| 18 | 18 | @default fn main() -> i32 { |
|
| 19 | - | if ORIGIN.x != 0 { return 1; } |
|
| 20 | - | if ORIGIN.y != 0 { return 2; } |
|
| 19 | + | assert ORIGIN.x == 0; |
|
| 20 | + | assert ORIGIN.y == 0; |
|
| 21 | 21 | ||
| 22 | - | if P1.x != 100 { return 3; } |
|
| 23 | - | if P1.y != -50 { return 4; } |
|
| 22 | + | assert P1.x == 100; |
|
| 23 | + | assert P1.y == -50; |
|
| 24 | 24 | ||
| 25 | - | if M1.a != 255 { return 5; } |
|
| 26 | - | if M1.b != 1000 { return 6; } |
|
| 27 | - | if M1.c != 100000 { return 7; } |
|
| 28 | - | if M1.d != true { return 8; } |
|
| 25 | + | assert M1.a == 255; |
|
| 26 | + | assert M1.b == 1000; |
|
| 27 | + | assert M1.c == 100000; |
|
| 28 | + | assert M1.d == true; |
|
| 29 | 29 | ||
| 30 | 30 | return 0; |
|
| 31 | 31 | } |
lib/std/arch/rv64/tests/data.u16.rad
+3 -3
| 2 | 2 | const A: u16 = 0; |
|
| 3 | 3 | const B: u16 = 32767; |
|
| 4 | 4 | const C: u16 = 65535; |
|
| 5 | 5 | ||
| 6 | 6 | @default fn main() -> i32 { |
|
| 7 | - | if A != 0 { return 1; } |
|
| 8 | - | if B != 32767 { return 2; } |
|
| 9 | - | if C != 65535 { return 3; } |
|
| 7 | + | assert A == 0; |
|
| 8 | + | assert B == 32767; |
|
| 9 | + | assert C == 65535; |
|
| 10 | 10 | ||
| 11 | 11 | return 0; |
|
| 12 | 12 | } |
lib/std/arch/rv64/tests/data.u32.rad
+3 -3
| 2 | 2 | const A: u32 = 0; |
|
| 3 | 3 | const B: u32 = 2147483647; |
|
| 4 | 4 | const C: u32 = 4294967295; |
|
| 5 | 5 | ||
| 6 | 6 | @default fn main() -> i32 { |
|
| 7 | - | if A != 0 { return 1; } |
|
| 8 | - | if B != 2147483647 { return 2; } |
|
| 9 | - | if C != 4294967295 { return 3; } |
|
| 7 | + | assert A == 0; |
|
| 8 | + | assert B == 2147483647; |
|
| 9 | + | assert C == 4294967295; |
|
| 10 | 10 | ||
| 11 | 11 | return 0; |
|
| 12 | 12 | } |
lib/std/arch/rv64/tests/data.u8.rad
+3 -3
| 2 | 2 | const A: u8 = 0; |
|
| 3 | 3 | const B: u8 = 127; |
|
| 4 | 4 | const C: u8 = 255; |
|
| 5 | 5 | ||
| 6 | 6 | @default fn main() -> i32 { |
|
| 7 | - | if A != 0 { return 1; } |
|
| 8 | - | if B != 127 { return 2; } |
|
| 9 | - | if C != 255 { return 3; } |
|
| 7 | + | assert A == 0; |
|
| 8 | + | assert B == 127; |
|
| 9 | + | assert C == 255; |
|
| 10 | 10 | ||
| 11 | 11 | return 0; |
|
| 12 | 12 | } |
lib/std/arch/rv64/tests/debug.tag.rad
+1 -3
| 8 | 8 | }, |
|
| 9 | 9 | } |
|
| 10 | 10 | ||
| 11 | 11 | @default fn main() -> u32 { |
|
| 12 | 12 | let padding: [u32; 600] = [0; 600]; |
|
| 13 | - | if padding[0] != 0 { |
|
| 14 | - | return 99; |
|
| 15 | - | } |
|
| 13 | + | assert padding[0] == 0; |
|
| 16 | 14 | ||
| 17 | 15 | let big: Huge = Huge::Large { |
|
| 18 | 16 | payload: [0; 32], |
|
| 19 | 17 | flag: 7, |
|
| 20 | 18 | }; |
lib/std/arch/rv64/tests/edge.cases.4.rad
+4 -6
| 40 | 40 | sign: Signedness::Signed, |
|
| 41 | 41 | }; |
|
| 42 | 42 | let case TypeSig::Integer { width: w1, .. } = direct |
|
| 43 | 43 | else return 50; |
|
| 44 | 44 | ||
| 45 | - | if w1 != 4 { |
|
| 46 | - | return 51; |
|
| 47 | - | } |
|
| 45 | + | assert w1 == 4; |
|
| 48 | 46 | let mut nodes: [Node; 2] = undefined; |
|
| 49 | - | let nodes_ptr: *mut Node = &mut nodes[0]; |
|
| 47 | + | let nodesPtr: *mut Node = &mut nodes[0]; |
|
| 50 | 48 | let mut count: u32 = 0; |
|
| 51 | - | let type_node = nodeTypeInt(nodes_ptr, &mut count, 4, Signedness::Signed); |
|
| 52 | - | let case NodeValue::TypeSig(sig) = type_node.value |
|
| 49 | + | let typeNode = nodeTypeInt(nodesPtr, &mut count, 4, Signedness::Signed); |
|
| 50 | + | let case NodeValue::TypeSig(sig) = typeNode.value |
|
| 53 | 51 | else return 40; |
|
| 54 | 52 | ||
| 55 | 53 | let case TypeSig::Integer { width: w2, .. } = sig |
|
| 56 | 54 | else return 41; |
|
| 57 | 55 |
lib/std/arch/rv64/tests/edge.cases.6.rad
+1 -3
| 99 | 99 | } |
|
| 100 | 100 | if ANALYZER.len != 1 { |
|
| 101 | 101 | // Bookkeeping field was overwritten by the bad store. |
|
| 102 | 102 | return 2; |
|
| 103 | 103 | } |
|
| 104 | - | if ANALYZER.pad0 != 0xDEADAAA0 or ANALYZER.pad1 != 0xDEADAAA1 { |
|
| 105 | - | return 4; |
|
| 106 | - | } |
|
| 104 | + | assert ANALYZER.pad0 == 0xDEADAAA0 and ANALYZER.pad1 == 0xDEADAAA1; |
|
| 107 | 105 | ||
| 108 | 106 | let stored = STORAGE[0]; |
|
| 109 | 107 | if stored.a != 0xAAAA1111 or stored.b != 0xBBBB2222 or stored.c != 0xCCCC3333 or stored.d != 0xDDDD4444 or stored.e != 0xEEEE5555 or stored.f != 0x12345601 or stored.j != 0x12345605 or stored.t != 0x1234560F { |
|
| 110 | 108 | // The write never hit the backing buffer. |
|
| 111 | 109 | return 3; |
lib/std/arch/rv64/tests/edge.cases.8.bug.rad
+1 -3
| 18 | 18 | } |
|
| 19 | 19 | ||
| 20 | 20 | @default fn main() -> i32 { |
|
| 21 | 21 | global = Outer { padding: 0, inner: Inner { value: 42 } }; |
|
| 22 | 22 | ||
| 23 | - | if readInner(global.inner) != 42 { |
|
| 24 | - | return 1; |
|
| 25 | - | } |
|
| 23 | + | assert readInner(global.inner) == 42; |
|
| 26 | 24 | return 0; |
|
| 27 | 25 | } |
lib/std/arch/rv64/tests/edge.cases.rad
+1 -3
| 2 | 2 | pub record Scanner { |
|
| 3 | 3 | source: *[u8], |
|
| 4 | 4 | } |
|
| 5 | 5 | ||
| 6 | 6 | fn peek(s: *Scanner) -> i32 { |
|
| 7 | - | if 0 + 0 > s.source.len { |
|
| 8 | - | return 1; |
|
| 9 | - | } |
|
| 7 | + | assert 0 + 0 <= s.source.len; |
|
| 10 | 8 | return 0; |
|
| 11 | 9 | } |
|
| 12 | 10 | ||
| 13 | 11 | @default fn main() -> i32 { |
|
| 14 | 12 | let s: Scanner = Scanner { source: "1" }; |
lib/std/arch/rv64/tests/error.catch.rad
+9 -9
| 21 | 21 | // Catch block with return in function |
|
| 22 | 22 | let val3: u32 = returnsEarly(); |
|
| 23 | 23 | assert val3 == 42; |
|
| 24 | 24 | ||
| 25 | 25 | // try? converts to optional on error |
|
| 26 | - | let ptr_ok: ?*i32 = try? returnsPtrOk(); |
|
| 27 | - | if let p = ptr_ok { |
|
| 26 | + | let ptrOk: ?*i32 = try? returnsPtrOk(); |
|
| 27 | + | if let p = ptrOk { |
|
| 28 | 28 | assert *p == 7; |
|
| 29 | 29 | } else { |
|
| 30 | 30 | assert false; |
|
| 31 | 31 | } |
|
| 32 | 32 | ||
| 33 | 33 | // try? converts to nil on error |
|
| 34 | - | let ptr_err: ?*i32 = try? returnsPtrErr(); |
|
| 35 | - | assert ptr_err == nil; |
|
| 34 | + | let ptrErr: ?*i32 = try? returnsPtrErr(); |
|
| 35 | + | assert ptrErr == nil; |
|
| 36 | 36 | ||
| 37 | 37 | // try? on success |
|
| 38 | - | let opt_ok: ?u32 = try? returnsOk(); |
|
| 39 | - | assert opt_ok != nil; |
|
| 40 | - | if let v = opt_ok { |
|
| 38 | + | let optOk: ?u32 = try? returnsOk(); |
|
| 39 | + | assert optOk != nil; |
|
| 40 | + | if let v = optOk { |
|
| 41 | 41 | assert v == 21; |
|
| 42 | 42 | } |
|
| 43 | 43 | ||
| 44 | 44 | // try? on error |
|
| 45 | - | let opt_err: ?u32 = try? returnsErr(); |
|
| 46 | - | assert opt_err == nil; |
|
| 45 | + | let optErr: ?u32 = try? returnsErr(); |
|
| 46 | + | assert optErr == nil; |
|
| 47 | 47 | ||
| 48 | 48 | return 0; |
|
| 49 | 49 | } |
|
| 50 | 50 | ||
| 51 | 51 | fn catchWithReturn(fail: bool) -> u32 { |
lib/std/arch/rv64/tests/error.multi.basic.rad
+3 -9
| 19 | 19 | // Test throwing ErrA. |
|
| 20 | 20 | let mut caught: i32 = 0; |
|
| 21 | 21 | try failA() catch { |
|
| 22 | 22 | caught = 1; |
|
| 23 | 23 | }; |
|
| 24 | - | if caught != 1 { |
|
| 25 | - | return 1; |
|
| 26 | - | } |
|
| 24 | + | assert caught == 1; |
|
| 27 | 25 | ||
| 28 | 26 | // Test throwing ErrB. |
|
| 29 | 27 | caught = 0; |
|
| 30 | 28 | try failB() catch { |
|
| 31 | 29 | caught = 2; |
|
| 32 | 30 | }; |
|
| 33 | - | if caught != 2 { |
|
| 34 | - | return 2; |
|
| 35 | - | } |
|
| 31 | + | assert caught == 2; |
|
| 36 | 32 | ||
| 37 | 33 | // Test success path. |
|
| 38 | 34 | let val = try succeed() catch { |
|
| 39 | 35 | return 3; |
|
| 40 | 36 | }; |
|
| 41 | - | if val != 42 { |
|
| 42 | - | return 4; |
|
| 43 | - | } |
|
| 37 | + | assert val == 42; |
|
| 44 | 38 | return 0; |
|
| 45 | 39 | } |
lib/std/arch/rv64/tests/error.multi.catch.rad
+4 -12
| 19 | 19 | // Catch ErrA without binding. |
|
| 20 | 20 | let mut handled: i32 = 0; |
|
| 21 | 21 | try failA() catch { |
|
| 22 | 22 | handled = 1; |
|
| 23 | 23 | }; |
|
| 24 | - | if handled != 1 { |
|
| 25 | - | return 1; |
|
| 26 | - | } |
|
| 24 | + | assert handled == 1; |
|
| 27 | 25 | ||
| 28 | 26 | // Catch ErrB without binding. |
|
| 29 | 27 | handled = 0; |
|
| 30 | 28 | try failB() catch { |
|
| 31 | 29 | handled = 2; |
|
| 32 | 30 | }; |
|
| 33 | - | if handled != 2 { |
|
| 34 | - | return 2; |
|
| 35 | - | } |
|
| 31 | + | assert handled == 2; |
|
| 36 | 32 | ||
| 37 | 33 | // Success path should not trigger catch. |
|
| 38 | 34 | handled = 0; |
|
| 39 | 35 | let val = try succeed() catch { |
|
| 40 | 36 | handled = 99; |
|
| 41 | 37 | }; |
|
| 42 | - | if handled != 0 { |
|
| 43 | - | return 3; |
|
| 44 | - | } |
|
| 45 | - | if val != 99 { |
|
| 46 | - | return 4; |
|
| 47 | - | } |
|
| 38 | + | assert handled == 0; |
|
| 39 | + | assert val == 99; |
|
| 48 | 40 | return 0; |
|
| 49 | 41 | } |
lib/std/arch/rv64/tests/error.multi.catch.typed.binding.rad
+2 -6
| 20 | 20 | }; |
|
| 21 | 21 | got = v; |
|
| 22 | 22 | } catch e as ErrB { |
|
| 23 | 23 | return 2; |
|
| 24 | 24 | }; |
|
| 25 | - | if got != 100 { |
|
| 26 | - | return 3; |
|
| 27 | - | } |
|
| 25 | + | assert got == 100; |
|
| 28 | 26 | ||
| 29 | 27 | // Extract ErrB payload. |
|
| 30 | 28 | got = 0; |
|
| 31 | 29 | try failB(200) catch e as ErrA { |
|
| 32 | 30 | return 4; |
| 34 | 32 | let case ErrB::B(v) = e else { |
|
| 35 | 33 | return 5; |
|
| 36 | 34 | }; |
|
| 37 | 35 | got = v; |
|
| 38 | 36 | }; |
|
| 39 | - | if got != 200 { |
|
| 40 | - | return 6; |
|
| 41 | - | } |
|
| 37 | + | assert got == 200; |
|
| 42 | 38 | return 0; |
|
| 43 | 39 | } |
lib/std/arch/rv64/tests/error.multi.catch.typed.catchall.rad
+7 -13
| 25 | 25 | }; |
|
| 26 | 26 | result = v; |
|
| 27 | 27 | } catch { |
|
| 28 | 28 | return 1; |
|
| 29 | 29 | }; |
|
| 30 | - | if result != 10 { |
|
| 31 | - | return 2; |
|
| 32 | - | } |
|
| 30 | + | assert result == 10; |
|
| 33 | 31 | ||
| 34 | 32 | // ErrB should fall into catch-all. |
|
| 35 | - | let mut caught_all: i32 = 0; |
|
| 33 | + | let mut caughtAll: i32 = 0; |
|
| 36 | 34 | try failB() catch e as ErrA { |
|
| 37 | 35 | return 3; |
|
| 38 | 36 | } catch { |
|
| 39 | - | caught_all = 1; |
|
| 37 | + | caughtAll = 1; |
|
| 40 | 38 | }; |
|
| 41 | - | if caught_all != 1 { |
|
| 42 | - | return 4; |
|
| 43 | - | } |
|
| 39 | + | assert caughtAll == 1; |
|
| 44 | 40 | ||
| 45 | 41 | // ErrC should also fall into catch-all. |
|
| 46 | - | caught_all = 0; |
|
| 42 | + | caughtAll = 0; |
|
| 47 | 43 | try failC() catch e as ErrA { |
|
| 48 | 44 | return 5; |
|
| 49 | 45 | } catch { |
|
| 50 | - | caught_all = 1; |
|
| 46 | + | caughtAll = 1; |
|
| 51 | 47 | }; |
|
| 52 | - | if caught_all != 1 { |
|
| 53 | - | return 6; |
|
| 54 | - | } |
|
| 48 | + | assert caughtAll == 1; |
|
| 55 | 49 | return 0; |
|
| 56 | 50 | } |
lib/std/arch/rv64/tests/error.multi.catch.typed.rad
+3 -9
| 25 | 25 | result = v; |
|
| 26 | 26 | 0 |
|
| 27 | 27 | } catch e as ErrB { |
|
| 28 | 28 | return 1; |
|
| 29 | 29 | }; |
|
| 30 | - | if result != 10 { |
|
| 31 | - | return 2; |
|
| 32 | - | } |
|
| 30 | + | assert result == 10; |
|
| 33 | 31 | ||
| 34 | 32 | // Catch ErrB specifically with typed binding. |
|
| 35 | 33 | result = 0; |
|
| 36 | 34 | let val2 = try failB() catch e as ErrA { |
|
| 37 | 35 | return 3; |
| 40 | 38 | return 11; |
|
| 41 | 39 | }; |
|
| 42 | 40 | result = v; |
|
| 43 | 41 | 0 |
|
| 44 | 42 | }; |
|
| 45 | - | if result != 20 { |
|
| 46 | - | return 4; |
|
| 47 | - | } |
|
| 43 | + | assert result == 20; |
|
| 48 | 44 | ||
| 49 | 45 | // Success path should skip all catches. |
|
| 50 | 46 | let val3 = try succeed() catch e as ErrA { |
|
| 51 | 47 | return 5; |
|
| 52 | 48 | } catch e as ErrB { |
|
| 53 | 49 | return 6; |
|
| 54 | 50 | }; |
|
| 55 | - | if val3 != 42 { |
|
| 56 | - | return 7; |
|
| 57 | - | } |
|
| 51 | + | assert val3 == 42; |
|
| 58 | 52 | return 0; |
|
| 59 | 53 | } |
lib/std/arch/rv64/tests/error.multi.propagate.multi.rad
+3 -9
| 24 | 24 | try outer(1) catch e as ErrA { |
|
| 25 | 25 | result = 10; |
|
| 26 | 26 | } catch e as ErrB { |
|
| 27 | 27 | result = 20; |
|
| 28 | 28 | }; |
|
| 29 | - | if result != 10 { |
|
| 30 | - | return 1; |
|
| 31 | - | } |
|
| 29 | + | assert result == 10; |
|
| 32 | 30 | ||
| 33 | 31 | // Propagate ErrB through outer. |
|
| 34 | 32 | result = 0; |
|
| 35 | 33 | try outer(2) catch e as ErrA { |
|
| 36 | 34 | result = 10; |
|
| 37 | 35 | } catch e as ErrB { |
|
| 38 | 36 | result = 20; |
|
| 39 | 37 | }; |
|
| 40 | - | if result != 20 { |
|
| 41 | - | return 2; |
|
| 42 | - | } |
|
| 38 | + | assert result == 20; |
|
| 43 | 39 | ||
| 44 | 40 | // Success path. |
|
| 45 | 41 | let val = try outer(0) catch e as ErrA { |
|
| 46 | 42 | return 3; |
|
| 47 | 43 | } catch e as ErrB { |
|
| 48 | 44 | return 4; |
|
| 49 | 45 | }; |
|
| 50 | - | if val != 101 { |
|
| 51 | - | return 5; |
|
| 52 | - | } |
|
| 46 | + | assert val == 101; |
|
| 53 | 47 | return 0; |
|
| 54 | 48 | } |
lib/std/arch/rv64/tests/error.multi.propagate.rad
+3 -9
| 25 | 25 | // Propagate ErrA through middle. |
|
| 26 | 26 | let mut caught: i32 = 0; |
|
| 27 | 27 | try middle(1) catch { |
|
| 28 | 28 | caught = 1; |
|
| 29 | 29 | }; |
|
| 30 | - | if caught != 1 { |
|
| 31 | - | return 1; |
|
| 32 | - | } |
|
| 30 | + | assert caught == 1; |
|
| 33 | 31 | ||
| 34 | 32 | // Propagate ErrB through middle. |
|
| 35 | 33 | caught = 0; |
|
| 36 | 34 | try middle(2) catch { |
|
| 37 | 35 | caught = 2; |
|
| 38 | 36 | }; |
|
| 39 | - | if caught != 2 { |
|
| 40 | - | return 2; |
|
| 41 | - | } |
|
| 37 | + | assert caught == 2; |
|
| 42 | 38 | ||
| 43 | 39 | // Success path. |
|
| 44 | 40 | let val = try middle(0) catch { |
|
| 45 | 41 | return 3; |
|
| 46 | 42 | }; |
|
| 47 | - | if val != 100 { |
|
| 48 | - | return 4; |
|
| 49 | - | } |
|
| 43 | + | assert val == 100; |
|
| 50 | 44 | return 0; |
|
| 51 | 45 | } |
lib/std/arch/rv64/tests/error.multi.try.optional.rad
+3 -9
| 12 | 12 | } |
|
| 13 | 13 | ||
| 14 | 14 | @default fn main() -> i32 { |
|
| 15 | 15 | // try? on failure should produce nil. |
|
| 16 | 16 | let r1 = try? failA(); |
|
| 17 | - | if r1 != nil { |
|
| 18 | - | return 1; |
|
| 19 | - | } |
|
| 17 | + | assert r1 == nil; |
|
| 20 | 18 | ||
| 21 | 19 | // try? on success should produce the value. |
|
| 22 | 20 | let r2 = try? succeed(); |
|
| 23 | - | if r2 == nil { |
|
| 24 | - | return 2; |
|
| 25 | - | } |
|
| 21 | + | assert r2 != nil; |
|
| 26 | 22 | let val = r2 else { |
|
| 27 | 23 | return 3; |
|
| 28 | 24 | }; |
|
| 29 | - | if val != 77 { |
|
| 30 | - | return 4; |
|
| 31 | - | } |
|
| 25 | + | assert val == 77; |
|
| 32 | 26 | return 0; |
|
| 33 | 27 | } |
lib/std/arch/rv64/tests/error.try.optional.rad
+11 -33
| 35 | 35 | } |
|
| 36 | 36 | ||
| 37 | 37 | @default fn main() -> i32 { |
|
| 38 | 38 | // Test 1: try? on success returns Some(value) |
|
| 39 | 39 | let result1: ?u32 = try? returnsOk(); |
|
| 40 | - | if result1 == nil { |
|
| 41 | - | return 1; |
|
| 42 | - | } |
|
| 40 | + | assert result1 != nil; |
|
| 43 | 41 | if let x = result1 { |
|
| 44 | - | if x != 42 { |
|
| 45 | - | return 2; |
|
| 46 | - | } |
|
| 42 | + | assert x == 42; |
|
| 47 | 43 | } |
|
| 48 | 44 | ||
| 49 | 45 | // Test 2: try? on error returns nil |
|
| 50 | 46 | let result2: ?u32 = try? returnsErr(); |
|
| 51 | - | if result2 != nil { |
|
| 52 | - | return 3; |
|
| 53 | - | } |
|
| 47 | + | assert result2 == nil; |
|
| 54 | 48 | ||
| 55 | 49 | // Test 3: try? with if-let pattern matching |
|
| 56 | 50 | if let value = try? returnsOk() { |
|
| 57 | - | if value != 42 { |
|
| 58 | - | return 4; |
|
| 59 | - | } |
|
| 51 | + | assert value == 42; |
|
| 60 | 52 | } else { |
|
| 61 | 53 | return 5; |
|
| 62 | 54 | } |
|
| 63 | 55 | ||
| 64 | 56 | // Test 4: try? with if-let on error path |
| 66 | 58 | return 6; |
|
| 67 | 59 | } |
|
| 68 | 60 | ||
| 69 | 61 | // Test 5: try? in non-throwing function |
|
| 70 | 62 | let result5: ?u32 = nonThrowingCaller(); |
|
| 71 | - | if result5 == nil { |
|
| 72 | - | return 7; |
|
| 73 | - | } |
|
| 63 | + | assert result5 != nil; |
|
| 74 | 64 | if let x = result5 { |
|
| 75 | - | if x != 42 { |
|
| 76 | - | return 8; |
|
| 77 | - | } |
|
| 65 | + | assert x == 42; |
|
| 78 | 66 | } |
|
| 79 | 67 | ||
| 80 | 68 | // Test 6: try? with record return type |
|
| 81 | 69 | let result8: ?Point = try? returnsOkPoint(); |
|
| 82 | - | if result8 == nil { |
|
| 83 | - | return 9; |
|
| 84 | - | } |
|
| 70 | + | assert result8 != nil; |
|
| 85 | 71 | if let p = result8 { |
|
| 86 | - | if p.x != 10 { |
|
| 87 | - | return 10; |
|
| 88 | - | } |
|
| 89 | - | if p.y != 20 { |
|
| 90 | - | return 11; |
|
| 91 | - | } |
|
| 72 | + | assert p.x == 10; |
|
| 73 | + | assert p.y == 20; |
|
| 92 | 74 | } |
|
| 93 | 75 | ||
| 94 | 76 | let result9: ?Point = try? returnsErrPoint(); |
|
| 95 | - | if result9 != nil { |
|
| 96 | - | return 12; |
|
| 97 | - | } |
|
| 77 | + | assert result9 == nil; |
|
| 98 | 78 | ||
| 99 | 79 | // Test 7: try? in while-let loop |
|
| 100 | 80 | let mut count: u32 = 0; |
|
| 101 | 81 | let mut iter: u32 = 0; |
|
| 102 | 82 | while let value = try? maybeValue(iter) { |
|
| 103 | 83 | count += value; |
|
| 104 | 84 | iter += 1; |
|
| 105 | 85 | } |
|
| 106 | - | if count != 6 { |
|
| 107 | - | return 13; |
|
| 108 | - | } |
|
| 86 | + | assert count == 6; |
|
| 109 | 87 | ||
| 110 | 88 | return 0; |
|
| 111 | 89 | } |
lib/std/arch/rv64/tests/error.try.rad
+18 -54
| 111 | 111 | } |
|
| 112 | 112 | ||
| 113 | 113 | @default fn main() -> i32 { |
|
| 114 | 114 | let mut sumFlag: u32 = 0; |
|
| 115 | 115 | let total: u32 = try! sumThree(); |
|
| 116 | - | if total != 39 { |
|
| 117 | - | return 1; |
|
| 118 | - | } |
|
| 116 | + | assert total == 39; |
|
| 119 | 117 | sumFlag = total; |
|
| 120 | 118 | ||
| 121 | 119 | let mut scOkFlag: u32 = 0; |
|
| 122 | 120 | let scVal: u32 = try! shortCircuit(true); |
|
| 123 | - | if scVal != 10 { |
|
| 124 | - | return 2; |
|
| 125 | - | } |
|
| 121 | + | assert scVal == 10; |
|
| 126 | 122 | scOkFlag = scVal; |
|
| 127 | 123 | ||
| 128 | 124 | let mut scErrFlag: u32 = 0; |
|
| 129 | 125 | try shortCircuit(false) catch {}; |
|
| 130 | - | if scErrFlag != 0 { |
|
| 131 | - | return 3; |
|
| 132 | - | } |
|
| 126 | + | assert scErrFlag == 0; |
|
| 133 | 127 | ||
| 134 | 128 | let mut aggFlag: u32 = 0; |
|
| 135 | 129 | let aggVal: u32 = try! aggregateTwo(); |
|
| 136 | - | if aggVal != 30 { |
|
| 137 | - | return 4; |
|
| 138 | - | } |
|
| 130 | + | assert aggVal == 30; |
|
| 139 | 131 | ||
| 140 | 132 | let mut casOkFlag: u32 = 0; |
|
| 141 | 133 | let casVal: u32 = try! cascade(false); |
|
| 142 | - | if casVal != 22 { |
|
| 143 | - | return 5; |
|
| 144 | - | } |
|
| 134 | + | assert casVal == 22; |
|
| 145 | 135 | ||
| 146 | 136 | let mut casErrFlag: u32 = 0; |
|
| 147 | 137 | try cascade(true) catch {}; |
|
| 148 | - | if casErrFlag != 0 { |
|
| 149 | - | return 6; |
|
| 150 | - | } |
|
| 138 | + | assert casErrFlag == 0; |
|
| 151 | 139 | ||
| 152 | 140 | let mut loopOkFlag: u32 = 0; |
|
| 153 | 141 | let loopVal: u32 = try! accumulateSteps(false); |
|
| 154 | - | if loopVal != 27 { |
|
| 155 | - | return 7; |
|
| 156 | - | } |
|
| 142 | + | assert loopVal == 27; |
|
| 157 | 143 | ||
| 158 | 144 | let mut loopErrFlag: u32 = 0; |
|
| 159 | 145 | try accumulateSteps(true) catch {}; |
|
| 160 | - | if loopErrFlag != 0 { |
|
| 161 | - | return 8; |
|
| 162 | - | } |
|
| 146 | + | assert loopErrFlag == 0; |
|
| 163 | 147 | ||
| 164 | 148 | let mut sink: ResultSink = ResultSink { last: 0, count: 0 }; |
|
| 165 | 149 | let sVal: u32 = try! structSuccess(&mut sink); |
|
| 166 | - | if sink.last != 21 { |
|
| 167 | - | return 9; |
|
| 168 | - | } |
|
| 169 | - | if sink.count != 1 { |
|
| 170 | - | return 10; |
|
| 171 | - | } |
|
| 150 | + | assert sink.last == 21; |
|
| 151 | + | assert sink.count == 1; |
|
| 172 | 152 | ||
| 173 | 153 | try structFailure(&mut sink) catch {}; |
|
| 174 | 154 | try! structSuccess(&mut sink); |
|
| 175 | 155 | try structFailure(&mut sink) catch {}; |
|
| 176 | - | if sink.count != 2 { |
|
| 177 | - | return 11; |
|
| 178 | - | } |
|
| 156 | + | assert sink.count == 2; |
|
| 179 | 157 | ||
| 180 | 158 | let mut voidOkFlag: u32 = 0; |
|
| 181 | 159 | try! returnsOkVoid(); |
|
| 182 | 160 | voidOkFlag = 77; |
|
| 183 | - | if voidOkFlag != 77 { |
|
| 184 | - | return 12; |
|
| 185 | - | } |
|
| 161 | + | assert voidOkFlag == 77; |
|
| 186 | 162 | ||
| 187 | 163 | let mut voidErrFlag: u32 = 0; |
|
| 188 | 164 | try returnsErrVoid() catch {}; |
|
| 189 | - | if voidErrFlag != 0 { |
|
| 190 | - | return 13; |
|
| 191 | - | } |
|
| 165 | + | assert voidErrFlag == 0; |
|
| 192 | 166 | ||
| 193 | 167 | let result: ?u32 = try? directThrow(); |
|
| 194 | - | if result != nil { |
|
| 195 | - | return 14; |
|
| 196 | - | } |
|
| 168 | + | assert result == nil; |
|
| 197 | 169 | ||
| 198 | 170 | let mut catchReturnFlag: u32 = 0; |
|
| 199 | 171 | let catchReturnFail: bool = catchReturn(&mut catchReturnFlag, true); |
|
| 200 | - | if not catchReturnFail { |
|
| 201 | - | return 15; |
|
| 202 | - | } |
|
| 203 | - | if catchReturnFlag != 0 { |
|
| 204 | - | return 16; |
|
| 205 | - | } |
|
| 172 | + | assert catchReturnFail; |
|
| 173 | + | assert catchReturnFlag == 0; |
|
| 206 | 174 | ||
| 207 | 175 | let catchReturnOk: bool = catchReturn(&mut catchReturnFlag, false); |
|
| 208 | - | if catchReturnOk { |
|
| 209 | - | return 17; |
|
| 210 | - | } |
|
| 211 | - | if catchReturnFlag != 77 { |
|
| 212 | - | return 18; |
|
| 213 | - | } |
|
| 176 | + | assert not catchReturnOk; |
|
| 177 | + | assert catchReturnFlag == 77; |
|
| 214 | 178 | ||
| 215 | 179 | return 0; |
|
| 216 | 180 | } |
lib/std/arch/rv64/tests/fn.callback.nested.rad
+1 -3
| 47 | 47 | ||
| 48 | 48 | // maxReg should be 6 (max register 5 + 1) |
|
| 49 | 49 | if maxReg == 6 { |
|
| 50 | 50 | return 0; |
|
| 51 | 51 | } |
|
| 52 | - | if maxReg > 255 { |
|
| 53 | - | return 255; |
|
| 54 | - | } |
|
| 52 | + | assert maxReg <= 255; |
|
| 55 | 53 | return maxReg as i32; |
|
| 56 | 54 | } |
lib/std/arch/rv64/tests/for.else.continue.rad
+2 -6
| 32 | 32 | fields[3] = Field { name: "bar", value: 40 }; |
|
| 33 | 33 | ||
| 34 | 34 | let v1 = findField(&fields[..], "foo") else { |
|
| 35 | 35 | return 1; |
|
| 36 | 36 | }; |
|
| 37 | - | if v1 != 20 { |
|
| 38 | - | return 2; |
|
| 39 | - | } |
|
| 37 | + | assert v1 == 20; |
|
| 40 | 38 | ||
| 41 | 39 | let v2 = findField(&fields[..], "bar") else { |
|
| 42 | 40 | return 3; |
|
| 43 | 41 | }; |
|
| 44 | - | if v2 != 40 { |
|
| 45 | - | return 4; |
|
| 46 | - | } |
|
| 42 | + | assert v2 == 40; |
|
| 47 | 43 | ||
| 48 | 44 | if let _ = findField(&fields[..], "baz") { |
|
| 49 | 45 | return 5; |
|
| 50 | 46 | } |
|
| 51 | 47 |
lib/std/arch/rv64/tests/frame.large.rad
+3 -9
| 19 | 19 | ||
| 20 | 20 | return ary[4091] as i32; |
|
| 21 | 21 | } |
|
| 22 | 22 | ||
| 23 | 23 | @default fn main() -> i32 { |
|
| 24 | - | if bigFrame1() != 491824 { |
|
| 25 | - | return 1; |
|
| 26 | - | } |
|
| 27 | - | if bigFrame2() != 7 { |
|
| 28 | - | return 2; |
|
| 29 | - | } |
|
| 30 | - | if bigFrame3() != 192 { |
|
| 31 | - | return 3; |
|
| 32 | - | } |
|
| 24 | + | assert bigFrame1() == 491824; |
|
| 25 | + | assert bigFrame2() == 7; |
|
| 26 | + | assert bigFrame3() == 192; |
|
| 33 | 27 | return 0; |
|
| 34 | 28 | } |
lib/std/arch/rv64/tests/iflet.shadow.leak.rad
+1 -3
| 4 | 4 | let mut x: i32 = 7; |
|
| 5 | 5 | let opt: ?i32 = 41; |
|
| 6 | 6 | ||
| 7 | 7 | if let x = opt { |
|
| 8 | 8 | // Inner pattern binding shadows outer `x`. |
|
| 9 | - | if x != 41 { |
|
| 10 | - | return 100; |
|
| 11 | - | } |
|
| 9 | + | assert x == 41; |
|
| 12 | 10 | } |
|
| 13 | 11 | ||
| 14 | 12 | // Must refer to outer x (7), not if-let binding (41). |
|
| 15 | 13 | return x; |
|
| 16 | 14 | } |
lib/std/arch/rv64/tests/integer.bitwise.basic.rad
+12 -12
| 1 | 1 | @default fn main() -> i32 { |
|
| 2 | 2 | let a: i32 = 12; // 0b1100 |
|
| 3 | 3 | let b: i32 = 5; // 0b0101 |
|
| 4 | 4 | ||
| 5 | - | let and_result: i32 = a & b; // 0b00100 |
|
| 6 | - | let or_result: i32 = a | b; // 0b01101 |
|
| 7 | - | let xor_result: i32 = a ^ b; // 0b01001 |
|
| 8 | - | let not_result: i32 = ~a; // 0b00011 |
|
| 9 | - | let lshift_result: i32 = a << 1; // 0b11000 |
|
| 10 | - | let rshift_result: i32 = a >> 2; // 0b00011 |
|
| 5 | + | let andResult: i32 = a & b; // 0b00100 |
|
| 6 | + | let orResult: i32 = a | b; // 0b01101 |
|
| 7 | + | let xorResult: i32 = a ^ b; // 0b01001 |
|
| 8 | + | let notResult: i32 = ~a; // 0b00011 |
|
| 9 | + | let lshiftResult: i32 = a << 1; // 0b11000 |
|
| 10 | + | let rshiftResult: i32 = a >> 2; // 0b00011 |
|
| 11 | 11 | ||
| 12 | - | if and_result != 4 { return (1) - 42; } |
|
| 13 | - | if or_result != 13 { return (1) - 42; } |
|
| 14 | - | if xor_result != 9 { return (1) - 42; } |
|
| 15 | - | if not_result != -13 { return (1) - 42; } |
|
| 16 | - | if lshift_result != 24 { return (1) - 42; } |
|
| 17 | - | if rshift_result != 3 { return (1) - 42; } |
|
| 12 | + | if andResult != 4 { return (1) - 42; } |
|
| 13 | + | if orResult != 13 { return (1) - 42; } |
|
| 14 | + | if xorResult != 9 { return (1) - 42; } |
|
| 15 | + | if notResult != -13 { return (1) - 42; } |
|
| 16 | + | if lshiftResult != 24 { return (1) - 42; } |
|
| 17 | + | if rshiftResult != 3 { return (1) - 42; } |
|
| 18 | 18 | ||
| 19 | 19 | return (42) - 42; |
|
| 20 | 20 | } |
lib/std/arch/rv64/tests/integer.overflow.rad
+10 -30
| 59 | 59 | let overflowResult: i16 = minI16 / -1 as i16; |
|
| 60 | 60 | return overflowResult == -32768; |
|
| 61 | 61 | } |
|
| 62 | 62 | ||
| 63 | 63 | @default fn main() -> i32 { |
|
| 64 | - | if not testI32Overflow() { |
|
| 65 | - | return 1; |
|
| 66 | - | } |
|
| 67 | - | if not testI32Underflow() { |
|
| 68 | - | return 2; |
|
| 69 | - | } |
|
| 70 | - | if not testU32Overflow() { |
|
| 71 | - | return 3; |
|
| 72 | - | } |
|
| 73 | - | if not testU32Underflow() { |
|
| 74 | - | return 4; |
|
| 75 | - | } |
|
| 76 | - | if not testI8Overflow() { |
|
| 77 | - | return 5; |
|
| 78 | - | } |
|
| 79 | - | if not testI8Underflow() { |
|
| 80 | - | return 6; |
|
| 81 | - | } |
|
| 82 | - | if not testU8Overflow() { |
|
| 83 | - | return 7; |
|
| 84 | - | } |
|
| 85 | - | if not testU8Underflow() { |
|
| 86 | - | return 8; |
|
| 87 | - | } |
|
| 88 | - | if not testI8DivOverflow() { |
|
| 89 | - | return 9; |
|
| 90 | - | } |
|
| 91 | - | if not testI16DivOverflow() { |
|
| 92 | - | return 10; |
|
| 93 | - | } |
|
| 64 | + | assert testI32Overflow(); |
|
| 65 | + | assert testI32Underflow(); |
|
| 66 | + | assert testU32Overflow(); |
|
| 67 | + | assert testU32Underflow(); |
|
| 68 | + | assert testI8Overflow(); |
|
| 69 | + | assert testI8Underflow(); |
|
| 70 | + | assert testU8Overflow(); |
|
| 71 | + | assert testU8Underflow(); |
|
| 72 | + | assert testI8DivOverflow(); |
|
| 73 | + | assert testI16DivOverflow(); |
|
| 94 | 74 | return 0; |
|
| 95 | 75 | } |
lib/std/arch/rv64/tests/large.blit.store.rad
+11 -33
| 21 | 21 | /// Generates `store w32 <imm> %0 2200` in IL, which triggers the |
|
| 22 | 22 | /// SCRATCH1 aliasing bug when adjustOffset clobbers the value. |
|
| 23 | 23 | fn storeLargeOffset() -> i32 { |
|
| 24 | 24 | let mut b: Big = undefined; |
|
| 25 | 25 | b.tag = 42; |
|
| 26 | - | if b.tag != 42 { |
|
| 27 | - | return 1; |
|
| 28 | - | } |
|
| 26 | + | assert b.tag == 42; |
|
| 29 | 27 | b.tag = 99; |
|
| 30 | - | if b.tag != 99 { |
|
| 31 | - | return 2; |
|
| 32 | - | } |
|
| 28 | + | assert b.tag == 99; |
|
| 33 | 29 | return 0; |
|
| 34 | 30 | } |
|
| 35 | 31 | ||
| 36 | 32 | /// Copy a >2047 byte struct (triggers blit offset overflow). |
|
| 37 | 33 | fn copyBig() -> i32 { |
| 41 | 37 | src.a[2199] = 30; |
|
| 42 | 38 | src.tag = 77; |
|
| 43 | 39 | ||
| 44 | 40 | let mut dst: Big = src; |
|
| 45 | 41 | ||
| 46 | - | if dst.a[0] != 10 { |
|
| 47 | - | return 1; |
|
| 48 | - | } |
|
| 49 | - | if dst.a[1000] != 20 { |
|
| 50 | - | return 2; |
|
| 51 | - | } |
|
| 52 | - | if dst.a[2199] != 30 { |
|
| 53 | - | return 3; |
|
| 54 | - | } |
|
| 55 | - | if dst.tag != 77 { |
|
| 56 | - | return 4; |
|
| 57 | - | } |
|
| 42 | + | assert dst.a[0] == 10; |
|
| 43 | + | assert dst.a[1000] == 20; |
|
| 44 | + | assert dst.a[2199] == 30; |
|
| 45 | + | assert dst.tag == 77; |
|
| 58 | 46 | return 0; |
|
| 59 | 47 | } |
|
| 60 | 48 | ||
| 61 | 49 | /// Mutate a copy to ensure the blit produced an independent copy. |
|
| 62 | 50 | fn copyIndependence() -> i32 { |
| 67 | 55 | ||
| 68 | 56 | let mut b: Big = a; |
|
| 69 | 57 | b.a[0] = 99; |
|
| 70 | 58 | b.tag = 200; |
|
| 71 | 59 | ||
| 72 | - | if a.a[0] != 1 { |
|
| 73 | - | return 1; |
|
| 74 | - | } |
|
| 75 | - | if a.tag != 100 { |
|
| 76 | - | return 2; |
|
| 77 | - | } |
|
| 78 | - | if b.a[0] != 99 { |
|
| 79 | - | return 3; |
|
| 80 | - | } |
|
| 81 | - | if b.a[2199] != 2 { |
|
| 82 | - | return 4; |
|
| 83 | - | } |
|
| 84 | - | if b.tag != 200 { |
|
| 85 | - | return 5; |
|
| 86 | - | } |
|
| 60 | + | assert a.a[0] == 1; |
|
| 61 | + | assert a.tag == 100; |
|
| 62 | + | assert b.a[0] == 99; |
|
| 63 | + | assert b.a[2199] == 2; |
|
| 64 | + | assert b.tag == 200; |
|
| 87 | 65 | return 0; |
|
| 88 | 66 | } |
|
| 89 | 67 | ||
| 90 | 68 | @default fn main() -> i32 { |
|
| 91 | 69 | let r1 = storeLargeOffset(); |
lib/std/arch/rv64/tests/literal.w64.rad
+6 -18
| 72 | 72 | } |
|
| 73 | 73 | return true; |
|
| 74 | 74 | } |
|
| 75 | 75 | ||
| 76 | 76 | @default fn main() -> i32 { |
|
| 77 | - | if not testU64MaxLiteral() { |
|
| 78 | - | return 1; |
|
| 79 | - | } |
|
| 80 | - | if not testI64MaxLiteral() { |
|
| 81 | - | return 2; |
|
| 82 | - | } |
|
| 83 | - | if not testI64MinLiteral() { |
|
| 84 | - | return 3; |
|
| 85 | - | } |
|
| 86 | - | if not testHexW64Literal() { |
|
| 87 | - | return 4; |
|
| 88 | - | } |
|
| 89 | - | if not testLargeI64Arith() { |
|
| 90 | - | return 5; |
|
| 91 | - | } |
|
| 92 | - | if not testU64Overflow32() { |
|
| 93 | - | return 6; |
|
| 94 | - | } |
|
| 77 | + | assert testU64MaxLiteral(); |
|
| 78 | + | assert testI64MaxLiteral(); |
|
| 79 | + | assert testI64MinLiteral(); |
|
| 80 | + | assert testHexW64Literal(); |
|
| 81 | + | assert testLargeI64Arith(); |
|
| 82 | + | assert testU64Overflow32(); |
|
| 95 | 83 | return 0; |
|
| 96 | 84 | } |
lib/std/arch/rv64/tests/loc.addr.offset.bug.rad
+1 -3
| 15 | 15 | @default fn main() -> i32 { |
|
| 16 | 16 | outer.inner.value = 42; |
|
| 17 | 17 | ||
| 18 | 18 | let ptr: *Inner = &outer.inner; |
|
| 19 | 19 | ||
| 20 | - | if (*ptr).value != 42 { |
|
| 21 | - | return 1; |
|
| 22 | - | } |
|
| 20 | + | assert (*ptr).value == 42; |
|
| 23 | 21 | return 0; |
|
| 24 | 22 | } |
lib/std/arch/rv64/tests/loc.addr.opt.to.opt.rad
+3 -5
| 7 | 7 | } |
|
| 8 | 8 | ||
| 9 | 9 | static container: Container = undefined; |
|
| 10 | 10 | ||
| 11 | 11 | @default fn main() -> i32 { |
|
| 12 | - | let source_opt: ?i32 = 42; |
|
| 12 | + | let sourceOpt: ?i32 = 42; |
|
| 13 | 13 | ||
| 14 | - | container.opt = source_opt; |
|
| 14 | + | container.opt = sourceOpt; |
|
| 15 | 15 | ||
| 16 | 16 | if let val = container.opt { |
|
| 17 | - | if val != 42 { |
|
| 18 | - | return 2; |
|
| 19 | - | } |
|
| 17 | + | assert val == 42; |
|
| 20 | 18 | return 0; |
|
| 21 | 19 | } else { |
|
| 22 | 20 | return 1; |
|
| 23 | 21 | } |
|
| 24 | 22 | } |
lib/std/arch/rv64/tests/loc.addr.optional.assign.rad
+1 -3
| 9 | 9 | ||
| 10 | 10 | @default fn main() -> i32 { |
|
| 11 | 11 | container.opt = 42; |
|
| 12 | 12 | ||
| 13 | 13 | if let val = container.opt { |
|
| 14 | - | if val != 42 { |
|
| 15 | - | return 2; |
|
| 16 | - | } |
|
| 14 | + | assert val == 42; |
|
| 17 | 15 | return 0; |
|
| 18 | 16 | } else { |
|
| 19 | 17 | return 1; |
|
| 20 | 18 | } |
|
| 21 | 19 | } |
lib/std/arch/rv64/tests/loc.addr.record.assign.rad
+1 -3
| 16 | 16 | @default fn main() -> i32 { |
|
| 17 | 17 | source.value = 42; |
|
| 18 | 18 | ||
| 19 | 19 | outer.inner = source; |
|
| 20 | 20 | ||
| 21 | - | if outer.inner.value != 42 { |
|
| 22 | - | return 1; |
|
| 23 | - | } |
|
| 21 | + | assert outer.inner.value == 42; |
|
| 24 | 22 | return 0; |
|
| 25 | 23 | } |
lib/std/arch/rv64/tests/loop.complex.flow.rad
+2 -6
| 36 | 36 | } |
|
| 37 | 37 | ||
| 38 | 38 | // val sequence: -2, -1, 0, 1, 2, 3 |
|
| 39 | 39 | // Err for val <= 0: errCount = 3 (for -2, -1, 0) |
|
| 40 | 40 | // Ok for val > 0: sum = 0 + 1 + 2 + 3 = 6 |
|
| 41 | - | if sum != 6 { |
|
| 42 | - | return 1; |
|
| 43 | - | } |
|
| 44 | - | if errCount != 3 { |
|
| 45 | - | return 2; |
|
| 46 | - | } |
|
| 41 | + | assert sum == 6; |
|
| 42 | + | assert errCount == 3; |
|
| 47 | 43 | ||
| 48 | 44 | return 0; |
|
| 49 | 45 | } |
lib/std/arch/rv64/tests/loop.sealblock.rad
+3 -9
| 10 | 10 | while i < 5 { |
|
| 11 | 11 | sum += i; |
|
| 12 | 12 | i += 1; |
|
| 13 | 13 | } |
|
| 14 | 14 | // sum = 0 + 1 + 2 + 3 + 4 = 10 |
|
| 15 | - | if sum != 10 { |
|
| 16 | - | return 1; |
|
| 17 | - | } |
|
| 15 | + | assert sum == 10; |
|
| 18 | 16 | ||
| 19 | 17 | // For loop with mutable variable. |
|
| 20 | 18 | let mut count: i32 = 0; |
|
| 21 | 19 | for j in 0..4 { |
|
| 22 | 20 | count += 1; |
|
| 23 | 21 | } |
|
| 24 | - | if count != 4 { |
|
| 25 | - | return 2; |
|
| 26 | - | } |
|
| 22 | + | assert count == 4; |
|
| 27 | 23 | ||
| 28 | 24 | // Nested pattern: mutable var with function call in loop. |
|
| 29 | 25 | let mut total: i32 = 0; |
|
| 30 | 26 | for k in 0..3 { |
|
| 31 | 27 | total += addOne(k); |
|
| 32 | 28 | } |
|
| 33 | 29 | // total = 1 + 2 + 3 = 6 |
|
| 34 | - | if total != 6 { |
|
| 35 | - | return 3; |
|
| 36 | - | } |
|
| 30 | + | assert total == 6; |
|
| 37 | 31 | ||
| 38 | 32 | return 0; |
|
| 39 | 33 | } |
|
| 40 | 34 | ||
| 41 | 35 | fn addOne(x: i32) -> i32 { |
lib/std/arch/rv64/tests/match.multi.seal.rad
+4 -12
| 20 | 20 | } |
|
| 21 | 21 | } |
|
| 22 | 22 | ||
| 23 | 23 | @default fn main() -> i32 { |
|
| 24 | 24 | // Multi-pattern first variant |
|
| 25 | - | if classify(Kind::A, 5) != 15 { |
|
| 26 | - | return 1; |
|
| 27 | - | } |
|
| 25 | + | assert classify(Kind::A, 5) == 15; |
|
| 28 | 26 | // Multi-pattern last variant |
|
| 29 | - | if classify(Kind::C, 5) != 15 { |
|
| 30 | - | return 2; |
|
| 31 | - | } |
|
| 27 | + | assert classify(Kind::C, 5) == 15; |
|
| 32 | 28 | // Single-pattern variant |
|
| 33 | - | if classify(Kind::D, 5) != 25 { |
|
| 34 | - | return 3; |
|
| 35 | - | } |
|
| 29 | + | assert classify(Kind::D, 5) == 25; |
|
| 36 | 30 | // Else branch - the critical path |
|
| 37 | - | if classify(Kind::E, 5) != 35 { |
|
| 38 | - | return 4; |
|
| 39 | - | } |
|
| 31 | + | assert classify(Kind::E, 5) == 35; |
|
| 40 | 32 | return 0; |
|
| 41 | 33 | } |
lib/std/arch/rv64/tests/match.multi.survive.rad
+4 -12
| 43 | 43 | } |
|
| 44 | 44 | ||
| 45 | 45 | @default fn main() -> i32 { |
|
| 46 | 46 | // Test multi-pattern match (Alpha) |
|
| 47 | 47 | let s1 = State { value: 5, kind: Kind::Alpha }; |
|
| 48 | - | if classify(s1) != 15 { |
|
| 49 | - | return 1; |
|
| 50 | - | } |
|
| 48 | + | assert classify(s1) == 15; |
|
| 51 | 49 | // Test multi-pattern match (Gamma) |
|
| 52 | 50 | let s2 = State { value: 5, kind: Kind::Gamma }; |
|
| 53 | - | if classify(s2) != 15 { |
|
| 54 | - | return 2; |
|
| 55 | - | } |
|
| 51 | + | assert classify(s2) == 15; |
|
| 56 | 52 | // Test single-pattern match (Delta) |
|
| 57 | 53 | let s3 = State { value: 5, kind: Kind::Delta }; |
|
| 58 | - | if classify(s3) != 25 { |
|
| 59 | - | return 3; |
|
| 60 | - | } |
|
| 54 | + | assert classify(s3) == 25; |
|
| 61 | 55 | // Test else branch (Epsilon) - the critical case |
|
| 62 | 56 | let s4 = State { value: 5, kind: Kind::Epsilon }; |
|
| 63 | - | if classify(s4) != 35 { |
|
| 64 | - | return 4; |
|
| 65 | - | } |
|
| 57 | + | assert classify(s4) == 35; |
|
| 66 | 58 | return 0; |
|
| 67 | 59 | } |
lib/std/arch/rv64/tests/match.mutref.push.rad
+5 -15
| 30 | 30 | @default fn main() -> i32 { |
|
| 31 | 31 | let mut buf: [u32; 8] = undefined; |
|
| 32 | 32 | buf[0] = 0; |
|
| 33 | 33 | let mut state = Sealed::No { items: U32List { data: &mut buf[0..8], len: 0 } }; |
|
| 34 | 34 | ||
| 35 | - | if not addToUnsealedBlock(&mut state, 42) { |
|
| 36 | - | return 1; |
|
| 37 | - | } |
|
| 38 | - | if not addToUnsealedBlock(&mut state, 99) { |
|
| 39 | - | return 2; |
|
| 40 | - | } |
|
| 35 | + | assert addToUnsealedBlock(&mut state, 42); |
|
| 36 | + | assert addToUnsealedBlock(&mut state, 99); |
|
| 41 | 37 | ||
| 42 | 38 | // Check that the state is still No with len=2. |
|
| 43 | 39 | let case Sealed::No { items } = state else { |
|
| 44 | 40 | return 3; |
|
| 45 | 41 | }; |
|
| 46 | - | if items.len != 2 { |
|
| 47 | - | return 4; |
|
| 48 | - | } |
|
| 49 | - | if items.data[0] != 42 { |
|
| 50 | - | return 5; |
|
| 51 | - | } |
|
| 52 | - | if items.data[1] != 99 { |
|
| 53 | - | return 6; |
|
| 54 | - | } |
|
| 42 | + | assert items.len == 2; |
|
| 43 | + | assert items.data[0] == 42; |
|
| 44 | + | assert items.data[1] == 99; |
|
| 55 | 45 | return 0; |
|
| 56 | 46 | } |
lib/std/arch/rv64/tests/match.mutref.union.rad
+2 -6
| 25 | 25 | } |
|
| 26 | 26 | ||
| 27 | 27 | @default fn main() -> i32 { |
|
| 28 | 28 | let mut d = Data { state: State::A { count: 10 }, value: 42 }; |
|
| 29 | 29 | let r1 = process(&mut d); |
|
| 30 | - | if r1 != 10 { |
|
| 31 | - | return 1; |
|
| 32 | - | } |
|
| 30 | + | assert r1 == 10; |
|
| 33 | 31 | let r2 = process(&mut d); |
|
| 34 | - | if r2 != 11 { |
|
| 35 | - | return 2; |
|
| 36 | - | } |
|
| 32 | + | assert r2 == 11; |
|
| 37 | 33 | return 0; |
|
| 38 | 34 | } |
lib/std/arch/rv64/tests/match.value.copy.rad
+6 -18
| 32 | 32 | return 1; |
|
| 33 | 33 | }; |
|
| 34 | 34 | // Overwrite the source - binding should be unaffected. |
|
| 35 | 35 | b.data = Data::None; |
|
| 36 | 36 | ||
| 37 | - | if pair.a != 10 { |
|
| 38 | - | return 2; |
|
| 39 | - | } |
|
| 40 | - | if pair.b != 20 { |
|
| 41 | - | return 3; |
|
| 42 | - | } |
|
| 37 | + | assert pair.a == 10; |
|
| 38 | + | assert pair.b == 20; |
|
| 43 | 39 | return 0; |
|
| 44 | 40 | } |
|
| 45 | 41 | ||
| 46 | 42 | /// Test if-let-case with aggregate payload. |
|
| 47 | 43 | fn testIfLetCase() -> i32 { |
| 49 | 45 | data: Data::Some { pair: Pair { a: 30, b: 40 } }, |
|
| 50 | 46 | }; |
|
| 51 | 47 | ||
| 52 | 48 | if let case Data::Some { pair } = b.data { |
|
| 53 | 49 | b.data = Data::None; |
|
| 54 | - | if pair.a != 30 { |
|
| 55 | - | return 5; |
|
| 56 | - | } |
|
| 57 | - | if pair.b != 40 { |
|
| 58 | - | return 6; |
|
| 59 | - | } |
|
| 50 | + | assert pair.a == 30; |
|
| 51 | + | assert pair.b == 40; |
|
| 60 | 52 | } else { |
|
| 61 | 53 | return 4; |
|
| 62 | 54 | } |
|
| 63 | 55 | return 0; |
|
| 64 | 56 | } |
| 70 | 62 | }; |
|
| 71 | 63 | ||
| 72 | 64 | match b.data { |
|
| 73 | 65 | case Data::Some { pair } => { |
|
| 74 | 66 | b.data = Data::None; |
|
| 75 | - | if pair.a != 50 { |
|
| 76 | - | return 8; |
|
| 77 | - | } |
|
| 78 | - | if pair.b != 60 { |
|
| 79 | - | return 9; |
|
| 80 | - | } |
|
| 67 | + | assert pair.a == 50; |
|
| 68 | + | assert pair.b == 60; |
|
| 81 | 69 | } |
|
| 82 | 70 | case Data::None => { |
|
| 83 | 71 | return 7; |
|
| 84 | 72 | } |
|
| 85 | 73 | } |
lib/std/arch/rv64/tests/match.void.then.or.rad
+7 -21
| 43 | 43 | } |
|
| 44 | 44 | ||
| 45 | 45 | @default fn main() -> i32 { |
|
| 46 | 46 | // Test Add (in or-branch) |
|
| 47 | 47 | let e1 = Expr { op: Op::Add, left: 3, right: 4 }; |
|
| 48 | - | if eval(e1) != 7 { |
|
| 49 | - | return 1; |
|
| 50 | - | } |
|
| 48 | + | assert eval(e1) == 7; |
|
| 51 | 49 | // Test Sub (in or-branch) |
|
| 52 | 50 | let e2 = Expr { op: Op::Sub, left: 10, right: 3 }; |
|
| 53 | - | if eval(e2) != 13 { |
|
| 54 | - | return 2; |
|
| 55 | - | } |
|
| 51 | + | assert eval(e2) == 13; |
|
| 56 | 52 | // Test Mul (else of or-branch) |
|
| 57 | 53 | let e3 = Expr { op: Op::Mul, left: 3, right: 4 }; |
|
| 58 | - | if eval(e3) != 12 { |
|
| 59 | - | return 3; |
|
| 60 | - | } |
|
| 54 | + | assert eval(e3) == 12; |
|
| 61 | 55 | // Test And (first multi-pattern case) |
|
| 62 | 56 | let e4 = Expr { op: Op::And, left: 0, right: 0 }; |
|
| 63 | - | if eval(e4) != -1 { |
|
| 64 | - | return 4; |
|
| 65 | - | } |
|
| 57 | + | assert eval(e4) == -1; |
|
| 66 | 58 | // Test Xor (last in multi-pattern case) |
|
| 67 | 59 | let e5 = Expr { op: Op::Xor, left: 0, right: 0 }; |
|
| 68 | - | if eval(e5) != -1 { |
|
| 69 | - | return 5; |
|
| 70 | - | } |
|
| 60 | + | assert eval(e5) == -1; |
|
| 71 | 61 | // Test Eq (second multi-pattern case) |
|
| 72 | 62 | let e6 = Expr { op: Op::Eq, left: 0, right: 0 }; |
|
| 73 | - | if eval(e6) != -2 { |
|
| 74 | - | return 6; |
|
| 75 | - | } |
|
| 63 | + | assert eval(e6) == -2; |
|
| 76 | 64 | // Test Div (else of or, uses multiply path) |
|
| 77 | 65 | let e7 = Expr { op: Op::Div, left: 5, right: 6 }; |
|
| 78 | - | if eval(e7) != 30 { |
|
| 79 | - | return 7; |
|
| 80 | - | } |
|
| 66 | + | assert eval(e7) == 30; |
|
| 81 | 67 | return 0; |
|
| 82 | 68 | } |
lib/std/arch/rv64/tests/mutref.loop.bug.rad
+4 -12
| 51 | 51 | return a + b; |
|
| 52 | 52 | } |
|
| 53 | 53 | ||
| 54 | 54 | @default fn main() -> i32 { |
|
| 55 | 55 | // Zero iterations: the critical regression case. |
|
| 56 | - | if testZeroIter(0) != 42 { |
|
| 57 | - | return 1; |
|
| 58 | - | } |
|
| 56 | + | assert testZeroIter(0) == 42; |
|
| 59 | 57 | // Non-zero iterations still work. |
|
| 60 | - | if testZeroIter(3) != 45 { |
|
| 61 | - | return 2; |
|
| 62 | - | } |
|
| 58 | + | assert testZeroIter(3) == 45; |
|
| 63 | 59 | // Accumulation: 0+0+1+2+3+4 = 10 |
|
| 64 | - | if testMultiIter() != 10 { |
|
| 65 | - | return 3; |
|
| 66 | - | } |
|
| 60 | + | assert testMultiIter() == 10; |
|
| 67 | 61 | // Multiple vars: 3 + 97 = 100 |
|
| 68 | - | if testMultipleVars() != 100 { |
|
| 69 | - | return 4; |
|
| 70 | - | } |
|
| 62 | + | assert testMultipleVars() == 100; |
|
| 71 | 63 | return 0; |
|
| 72 | 64 | } |
lib/std/arch/rv64/tests/opt.if.let.complex.rad
+13 -39
| 262 | 262 | } |
|
| 263 | 263 | return false; |
|
| 264 | 264 | } |
|
| 265 | 265 | ||
| 266 | 266 | @default fn main() -> i32 { |
|
| 267 | - | if not testOptionalTypes() { |
|
| 268 | - | return 1; |
|
| 269 | - | } |
|
| 270 | - | if not testComplexCoercion() { |
|
| 271 | - | return 2; |
|
| 272 | - | } |
|
| 273 | - | if not testVariableShadowing() { |
|
| 274 | - | return 3; |
|
| 275 | - | } |
|
| 276 | - | if not testBoundaryValues() { |
|
| 277 | - | return 4; |
|
| 278 | - | } |
|
| 279 | - | if not testZeroGuardCondition() { |
|
| 280 | - | return 5; |
|
| 281 | - | } |
|
| 282 | - | if not testMultipleNilAssignments() { |
|
| 283 | - | return 6; |
|
| 284 | - | } |
|
| 285 | - | if not testNestedSameVariableGuards() { |
|
| 286 | - | return 7; |
|
| 287 | - | } |
|
| 288 | - | if not testComplexGuardExpressions() { |
|
| 289 | - | return 8; |
|
| 290 | - | } |
|
| 291 | - | if not testArithmeticInGuards() { |
|
| 292 | - | return 9; |
|
| 293 | - | } |
|
| 294 | - | if not testEarlyReturnGuardFailure() { |
|
| 295 | - | return 10; |
|
| 296 | - | } |
|
| 297 | - | if not testSequentialNilChecks() { |
|
| 298 | - | return 11; |
|
| 299 | - | } |
|
| 300 | - | if not testMixedIfTypes() { |
|
| 301 | - | return 12; |
|
| 302 | - | } |
|
| 303 | - | if not testOptionalAssignmentChains() { |
|
| 304 | - | return 13; |
|
| 305 | - | } |
|
| 267 | + | assert testOptionalTypes(); |
|
| 268 | + | assert testComplexCoercion(); |
|
| 269 | + | assert testVariableShadowing(); |
|
| 270 | + | assert testBoundaryValues(); |
|
| 271 | + | assert testZeroGuardCondition(); |
|
| 272 | + | assert testMultipleNilAssignments(); |
|
| 273 | + | assert testNestedSameVariableGuards(); |
|
| 274 | + | assert testComplexGuardExpressions(); |
|
| 275 | + | assert testArithmeticInGuards(); |
|
| 276 | + | assert testEarlyReturnGuardFailure(); |
|
| 277 | + | assert testSequentialNilChecks(); |
|
| 278 | + | assert testMixedIfTypes(); |
|
| 279 | + | assert testOptionalAssignmentChains(); |
|
| 306 | 280 | return 0; |
|
| 307 | 281 | } |
lib/std/arch/rv64/tests/opt.nil.check.rad
+2 -6
| 16 | 16 | let p = makeAlignedPtr(); |
|
| 17 | 17 | let opt: ?*u8 = p; |
|
| 18 | 18 | ||
| 19 | 19 | // The pointer is not nil, but its low byte is 0x00. |
|
| 20 | 20 | // A W8 comparison would wrongly say it's nil. |
|
| 21 | - | if opt == nil { |
|
| 22 | - | return 1; |
|
| 23 | - | } |
|
| 21 | + | assert opt != nil; |
|
| 24 | 22 | if let v = opt { |
|
| 25 | 23 | // Good: correctly identified as non-nil. |
|
| 26 | 24 | return 0; |
|
| 27 | 25 | } |
|
| 28 | 26 | return 2; |
| 35 | 33 | let offset: u64 = 256 - (base % 256); |
|
| 36 | 34 | // Create a slice starting at an address whose low byte is 0. |
|
| 37 | 35 | let s: *[u8] = &arr[offset as u32 ..]; |
|
| 38 | 36 | ||
| 39 | 37 | let opt: ?*[u8] = s; |
|
| 40 | - | if opt == nil { |
|
| 41 | - | return 1; |
|
| 42 | - | } |
|
| 38 | + | assert opt != nil; |
|
| 43 | 39 | if let v = opt { |
|
| 44 | 40 | return 0; |
|
| 45 | 41 | } |
|
| 46 | 42 | return 2; |
|
| 47 | 43 | } |
lib/std/arch/rv64/tests/opt.record.eq.rad
+15 -15
| 9 | 9 | record Outer { |
|
| 10 | 10 | item: ?Inner, |
|
| 11 | 11 | } |
|
| 12 | 12 | ||
| 13 | 13 | @default fn main() -> bool { |
|
| 14 | - | let outer_a = Outer { item: Inner { start: 3, end: 9 } }; |
|
| 15 | - | let outer_b = Outer { item: Inner { start: 3, end: 9 } }; |
|
| 14 | + | let outerA = Outer { item: Inner { start: 3, end: 9 } }; |
|
| 15 | + | let outerB = Outer { item: Inner { start: 3, end: 9 } }; |
|
| 16 | 16 | ||
| 17 | - | if outer_a != outer_b { |
|
| 17 | + | if outerA != outerB { |
|
| 18 | 18 | return false; |
|
| 19 | 19 | } |
|
| 20 | 20 | ||
| 21 | - | let outer_c = Outer { item: Inner { start: 4, end: 6 } }; |
|
| 22 | - | if outer_a == outer_c { |
|
| 21 | + | let outerC = Outer { item: Inner { start: 4, end: 6 } }; |
|
| 22 | + | if outerA == outerC { |
|
| 23 | 23 | return false; |
|
| 24 | 24 | } |
|
| 25 | 25 | ||
| 26 | - | let mut opt_a: ?Outer = nil; |
|
| 27 | - | let mut opt_b: ?Outer = nil; |
|
| 28 | - | let mut opt_diff: ?Outer = nil; |
|
| 29 | - | let mut opt_nil: ?Outer = nil; |
|
| 26 | + | let mut optA: ?Outer = nil; |
|
| 27 | + | let mut optB: ?Outer = nil; |
|
| 28 | + | let mut optDiff: ?Outer = nil; |
|
| 29 | + | let mut optNil: ?Outer = nil; |
|
| 30 | 30 | ||
| 31 | - | opt_a = outer_a; |
|
| 32 | - | opt_b = outer_b; |
|
| 33 | - | opt_diff = outer_c; |
|
| 31 | + | optA = outerA; |
|
| 32 | + | optB = outerB; |
|
| 33 | + | optDiff = outerC; |
|
| 34 | 34 | ||
| 35 | - | if opt_a != opt_b { |
|
| 35 | + | if optA != optB { |
|
| 36 | 36 | return false; |
|
| 37 | 37 | } |
|
| 38 | - | if opt_a == opt_diff { |
|
| 38 | + | if optA == optDiff { |
|
| 39 | 39 | return false; |
|
| 40 | 40 | } |
|
| 41 | - | if opt_a == opt_nil { |
|
| 41 | + | if optA == optNil { |
|
| 42 | 42 | return false; |
|
| 43 | 43 | } |
|
| 44 | 44 | return true; |
|
| 45 | 45 | } |
lib/std/arch/rv64/tests/opt.record.rad
+2 -2
| 9 | 9 | ||
| 10 | 10 | record Wrapper { |
|
| 11 | 11 | opt: ?i32, |
|
| 12 | 12 | } |
|
| 13 | 13 | ||
| 14 | - | fn take_optional(x: ?i32) -> i32 { |
|
| 14 | + | fn takeOptional(x: ?i32) -> i32 { |
|
| 15 | 15 | if let value = x { |
|
| 16 | 16 | return value; |
|
| 17 | 17 | } |
|
| 18 | 18 | return 0; |
|
| 19 | 19 | } |
| 35 | 35 | total += value; |
|
| 36 | 36 | } else { |
|
| 37 | 37 | return 0; |
|
| 38 | 38 | } |
|
| 39 | 39 | ||
| 40 | - | let call = take_optional(9); |
|
| 40 | + | let call = takeOptional(9); |
|
| 41 | 41 | return total + call; |
|
| 42 | 42 | } |
lib/std/arch/rv64/tests/opt.return.nested.rad
+2 -2
| 21 | 21 | } |
|
| 22 | 22 | ||
| 23 | 23 | @default fn main() -> u32 { |
|
| 24 | 24 | if let outer = nest(true, true) { |
|
| 25 | 25 | if let pair = outer; pair.x == 10 and pair.y == 89 { |
|
| 26 | - | if let outer_some_nil = nest(true, false) { |
|
| 27 | - | if let inner_nil = outer_some_nil { |
|
| 26 | + | if let outerSomeNil = nest(true, false) { |
|
| 27 | + | if let innerNil = outerSomeNil { |
|
| 28 | 28 | return 11; |
|
| 29 | 29 | } |
|
| 30 | 30 | } else { |
|
| 31 | 31 | return 12; |
|
| 32 | 32 | } |
lib/std/arch/rv64/tests/opt.slice.npo.rad
+16 -48
| 2 | 2 | //! Optional slices should have the same size as slices (16 bytes), |
|
| 3 | 3 | //! using a null data pointer to represent `nil`. |
|
| 4 | 4 | ||
| 5 | 5 | fn checkSizes() -> u8 { |
|
| 6 | 6 | // ?*[T] should be the same size as *[T] (16 bytes, not 24). |
|
| 7 | - | if @sizeOf(?*[u8]) != 16 { |
|
| 8 | - | return 1; |
|
| 9 | - | } |
|
| 10 | - | if @alignOf(?*[u8]) != 8 { |
|
| 11 | - | return 2; |
|
| 12 | - | } |
|
| 13 | - | if @sizeOf(?*[u16]) != 16 { |
|
| 14 | - | return 3; |
|
| 15 | - | } |
|
| 16 | - | if @sizeOf(?*mut [u8]) != 16 { |
|
| 17 | - | return 4; |
|
| 18 | - | } |
|
| 7 | + | assert @sizeOf(?*[u8]) == 16; |
|
| 8 | + | assert @alignOf(?*[u8]) == 8; |
|
| 9 | + | assert @sizeOf(?*[u16]) == 16; |
|
| 10 | + | assert @sizeOf(?*mut [u8]) == 16; |
|
| 19 | 11 | return 0; |
|
| 20 | 12 | } |
|
| 21 | 13 | ||
| 22 | 14 | fn checkNil() -> u8 { |
|
| 23 | 15 | let x: ?*[u8] = nil; |
|
| 24 | - | if x != nil { |
|
| 25 | - | return 10; |
|
| 26 | - | } |
|
| 16 | + | assert x == nil; |
|
| 27 | 17 | return 0; |
|
| 28 | 18 | } |
|
| 29 | 19 | ||
| 30 | 20 | fn checkWrap() -> u8 { |
|
| 31 | 21 | let arr: [u8; 3] = [1, 2, 3]; |
|
| 32 | 22 | let s = &arr[..]; |
|
| 33 | 23 | let opt: ?*[u8] = s; |
|
| 34 | 24 | ||
| 35 | - | if opt == nil { |
|
| 36 | - | return 20; |
|
| 37 | - | } |
|
| 25 | + | assert opt != nil; |
|
| 38 | 26 | return 0; |
|
| 39 | 27 | } |
|
| 40 | 28 | ||
| 41 | 29 | fn checkIfLet() -> u8 { |
|
| 42 | 30 | let arr: [u8; 3] = [10, 20, 30]; |
|
| 43 | 31 | let s = &arr[..]; |
|
| 44 | 32 | let opt: ?*[u8] = s; |
|
| 45 | 33 | ||
| 46 | 34 | if let val = opt { |
|
| 47 | - | if val.len != 3 { |
|
| 48 | - | return 31; |
|
| 49 | - | } |
|
| 50 | - | if val[0] != 10 { |
|
| 51 | - | return 32; |
|
| 52 | - | } |
|
| 53 | - | if val[1] != 20 { |
|
| 54 | - | return 33; |
|
| 55 | - | } |
|
| 35 | + | assert val.len == 3; |
|
| 36 | + | assert val[0] == 10; |
|
| 37 | + | assert val[1] == 20; |
|
| 56 | 38 | } else { |
|
| 57 | 39 | return 34; |
|
| 58 | 40 | } |
|
| 59 | 41 | ||
| 60 | 42 | let none: ?*[u8] = nil; |
| 70 | 52 | let opt: ?*[u8] = s; |
|
| 71 | 53 | ||
| 72 | 54 | let val = opt else { |
|
| 73 | 55 | return 40; |
|
| 74 | 56 | }; |
|
| 75 | - | if val.len != 3 { |
|
| 76 | - | return 41; |
|
| 77 | - | } |
|
| 57 | + | assert val.len == 3; |
|
| 78 | 58 | return 0; |
|
| 79 | 59 | } |
|
| 80 | 60 | ||
| 81 | 61 | fn returnNil() -> ?*[u8] { |
|
| 82 | 62 | return nil; |
| 87 | 67 | return &arr[..]; |
|
| 88 | 68 | } |
|
| 89 | 69 | ||
| 90 | 70 | fn checkReturn() -> u8 { |
|
| 91 | 71 | let a = returnNil(); |
|
| 92 | - | if a != nil { |
|
| 93 | - | return 50; |
|
| 94 | - | } |
|
| 72 | + | assert a == nil; |
|
| 95 | 73 | let b = returnSome(); |
|
| 96 | - | if b == nil { |
|
| 97 | - | return 51; |
|
| 98 | - | } |
|
| 74 | + | assert b != nil; |
|
| 99 | 75 | if let val = b { |
|
| 100 | - | if val[0] != 42 { |
|
| 101 | - | return 52; |
|
| 102 | - | } |
|
| 76 | + | assert val[0] == 42; |
|
| 103 | 77 | } else { |
|
| 104 | 78 | return 53; |
|
| 105 | 79 | } |
|
| 106 | 80 | return 0; |
|
| 107 | 81 | } |
| 131 | 105 | fn checkEq() -> u8 { |
|
| 132 | 106 | let a: ?*[u8] = nil; |
|
| 133 | 107 | let b: ?*[u8] = nil; |
|
| 134 | 108 | ||
| 135 | 109 | // nil == nil |
|
| 136 | - | if a != b { |
|
| 137 | - | return 70; |
|
| 138 | - | } |
|
| 110 | + | assert a == b; |
|
| 139 | 111 | ||
| 140 | 112 | let arr: [u8; 2] = [1, 2]; |
|
| 141 | 113 | let s = &arr[..]; |
|
| 142 | 114 | let c: ?*[u8] = s; |
|
| 143 | 115 | ||
| 144 | 116 | // some != nil |
|
| 145 | - | if c == a { |
|
| 146 | - | return 71; |
|
| 147 | - | } |
|
| 117 | + | assert c != a; |
|
| 148 | 118 | ||
| 149 | 119 | // some == some (same pointer) |
|
| 150 | 120 | let d: ?*[u8] = s; |
|
| 151 | - | if c != d { |
|
| 152 | - | return 72; |
|
| 153 | - | } |
|
| 121 | + | assert c == d; |
|
| 154 | 122 | ||
| 155 | 123 | return 0; |
|
| 156 | 124 | } |
|
| 157 | 125 | ||
| 158 | 126 | @default fn main() -> u8 { |
lib/std/arch/rv64/tests/opt.while.let.complex.rad
+1 -3
| 17 | 17 | sum += x; |
|
| 18 | 18 | cur = x; |
|
| 19 | 19 | } |
|
| 20 | 20 | ||
| 21 | 21 | // sum should be 6 + 5 + 4 + 3 + 2 = 20 |
|
| 22 | - | if sum != 20 { |
|
| 23 | - | return 1; |
|
| 24 | - | } |
|
| 22 | + | assert sum == 20; |
|
| 25 | 23 | return 0; |
|
| 26 | 24 | } |
lib/std/arch/rv64/tests/placeholder.comprehensive.rad
+1 -3
| 21 | 21 | let arr: [i32; 3] = [1, 2, 3]; |
|
| 22 | 22 | let mut count: i32 = 0; |
|
| 23 | 23 | for _ in &arr[..] { |
|
| 24 | 24 | count += 1; |
|
| 25 | 25 | } |
|
| 26 | - | if count != 3 { |
|
| 27 | - | return 3; |
|
| 28 | - | } |
|
| 26 | + | assert count == 3; |
|
| 29 | 27 | return 0; |
|
| 30 | 28 | } |
lib/std/arch/rv64/tests/pointer.copy.edge.case.rad
+1 -3
| 51 | 51 | let node: *mut Node = makeNode(&mut parser, NodeKind::Bool(true)); |
|
| 52 | 52 | setLen(node, 4); |
|
| 53 | 53 | ||
| 54 | 54 | match parser.nodes[0].kind { |
|
| 55 | 55 | case NodeKind::Bool(value) => { |
|
| 56 | - | if not value { |
|
| 57 | - | return 1; |
|
| 58 | - | } |
|
| 56 | + | assert value; |
|
| 59 | 57 | } |
|
| 60 | 58 | case NodeKind::Placeholder => { |
|
| 61 | 59 | return 2; |
|
| 62 | 60 | } |
|
| 63 | 61 | } |
lib/std/arch/rv64/tests/pointer.slice.store.rad
+4 -12
| 27 | 27 | ||
| 28 | 28 | HOLDER.ptr = &mut TABLE.entries; |
|
| 29 | 29 | ||
| 30 | 30 | HOLDER.ptr[0] = Entry { a: 1, b: 2, c: 3, d: 4, e: 5 }; |
|
| 31 | 31 | ||
| 32 | - | if TABLE.entries.len != 2 or TABLE.entries.ptr != &STORAGE[0] { |
|
| 33 | - | return 1; |
|
| 34 | - | } |
|
| 35 | - | if STORAGE[0].a != 1 or STORAGE[0].e != 5 { |
|
| 36 | - | return 2; |
|
| 37 | - | } |
|
| 32 | + | assert TABLE.entries.len == 2 and TABLE.entries.ptr == &STORAGE[0]; |
|
| 33 | + | assert STORAGE[0].a == 1 and STORAGE[0].e == 5; |
|
| 38 | 34 | ||
| 39 | 35 | HOLDER.ptr[1] = Entry { a: 10, b: 20, c: 30, d: 40, e: 50 }; |
|
| 40 | 36 | ||
| 41 | - | if TABLE.entries.len != 2 or TABLE.entries.ptr != &STORAGE[0] { |
|
| 42 | - | return 3; |
|
| 43 | - | } |
|
| 44 | - | if STORAGE[1].c != 30 or STORAGE[1].d != 40 { |
|
| 45 | - | return 4; |
|
| 46 | - | } |
|
| 37 | + | assert TABLE.entries.len == 2 and TABLE.entries.ptr == &STORAGE[0]; |
|
| 38 | + | assert STORAGE[1].c == 30 and STORAGE[1].d == 40; |
|
| 47 | 39 | return 0; |
|
| 48 | 40 | } |
lib/std/arch/rv64/tests/prog.ackermann.rad
+25 -75
| 65 | 65 | } |
|
| 66 | 66 | ||
| 67 | 67 | /// Test known small values using the recursive implementation. |
|
| 68 | 68 | fn testSmallRecursive() -> i32 { |
|
| 69 | 69 | // A(0, 0) = 1 |
|
| 70 | - | if ack(0, 0) != 1 { |
|
| 71 | - | return 1; |
|
| 72 | - | } |
|
| 70 | + | assert ack(0, 0) == 1; |
|
| 73 | 71 | // A(0, 5) = 6 |
|
| 74 | - | if ack(0, 5) != 6 { |
|
| 75 | - | return 2; |
|
| 76 | - | } |
|
| 72 | + | assert ack(0, 5) == 6; |
|
| 77 | 73 | // A(1, 0) = 2 |
|
| 78 | - | if ack(1, 0) != 2 { |
|
| 79 | - | return 3; |
|
| 80 | - | } |
|
| 74 | + | assert ack(1, 0) == 2; |
|
| 81 | 75 | // A(1, 5) = 7 |
|
| 82 | - | if ack(1, 5) != 7 { |
|
| 83 | - | return 4; |
|
| 84 | - | } |
|
| 76 | + | assert ack(1, 5) == 7; |
|
| 85 | 77 | // A(2, 0) = 3 |
|
| 86 | - | if ack(2, 0) != 3 { |
|
| 87 | - | return 5; |
|
| 88 | - | } |
|
| 78 | + | assert ack(2, 0) == 3; |
|
| 89 | 79 | // A(2, 3) = 9 |
|
| 90 | - | if ack(2, 3) != 9 { |
|
| 91 | - | return 6; |
|
| 92 | - | } |
|
| 80 | + | assert ack(2, 3) == 9; |
|
| 93 | 81 | // A(2, 4) = 11 |
|
| 94 | - | if ack(2, 4) != 11 { |
|
| 95 | - | return 7; |
|
| 96 | - | } |
|
| 82 | + | assert ack(2, 4) == 11; |
|
| 97 | 83 | // A(3, 0) = 5 |
|
| 98 | - | if ack(3, 0) != 5 { |
|
| 99 | - | return 8; |
|
| 100 | - | } |
|
| 84 | + | assert ack(3, 0) == 5; |
|
| 101 | 85 | // A(3, 1) = 13 |
|
| 102 | - | if ack(3, 1) != 13 { |
|
| 103 | - | return 9; |
|
| 104 | - | } |
|
| 86 | + | assert ack(3, 1) == 13; |
|
| 105 | 87 | // A(3, 2) = 29 |
|
| 106 | - | if ack(3, 2) != 29 { |
|
| 107 | - | return 10; |
|
| 108 | - | } |
|
| 88 | + | assert ack(3, 2) == 29; |
|
| 109 | 89 | // A(3, 3) = 61 |
|
| 110 | - | if ack(3, 3) != 61 { |
|
| 111 | - | return 11; |
|
| 112 | - | } |
|
| 90 | + | assert ack(3, 3) == 61; |
|
| 113 | 91 | // A(3, 4) = 125 |
|
| 114 | - | if ack(3, 4) != 125 { |
|
| 115 | - | return 12; |
|
| 116 | - | } |
|
| 92 | + | assert ack(3, 4) == 125; |
|
| 117 | 93 | return 0; |
|
| 118 | 94 | } |
|
| 119 | 95 | ||
| 120 | 96 | /// Test the memoized version against known values. |
|
| 121 | 97 | fn testMemoized() -> i32 { |
|
| 122 | 98 | // Verify m=0 row. |
|
| 123 | 99 | let mut n: u32 = 0; |
|
| 124 | 100 | while n < 50 { |
|
| 125 | 101 | let expected: i32 = n as i32 + 1; |
|
| 126 | - | if ackMemo(0, n) != expected { |
|
| 127 | - | return 1; |
|
| 128 | - | } |
|
| 102 | + | assert ackMemo(0, n) == expected; |
|
| 129 | 103 | n += 1; |
|
| 130 | 104 | } |
|
| 131 | 105 | ||
| 132 | 106 | // Verify m=1 row. |
|
| 133 | 107 | n = 0; |
|
| 134 | 108 | while n < 50 { |
|
| 135 | 109 | let expected: i32 = n as i32 + 2; |
|
| 136 | - | if ackMemo(1, n) != expected { |
|
| 137 | - | return 2; |
|
| 138 | - | } |
|
| 110 | + | assert ackMemo(1, n) == expected; |
|
| 139 | 111 | n += 1; |
|
| 140 | 112 | } |
|
| 141 | 113 | ||
| 142 | 114 | // Verify m=2 row. |
|
| 143 | 115 | n = 0; |
|
| 144 | 116 | while n < 50 { |
|
| 145 | 117 | let expected: i32 = (2 * n + 3) as i32; |
|
| 146 | - | if ackMemo(2, n) != expected { |
|
| 147 | - | return 3; |
|
| 148 | - | } |
|
| 118 | + | assert ackMemo(2, n) == expected; |
|
| 149 | 119 | n += 1; |
|
| 150 | 120 | } |
|
| 151 | 121 | ||
| 152 | 122 | // Verify m=3 row for small n. |
|
| 153 | 123 | // A(3,0)=5, A(3,1)=13, A(3,2)=29, A(3,3)=61, A(3,4)=125 |
|
| 154 | - | if ackMemo(3, 0) != 5 { |
|
| 155 | - | return 4; |
|
| 156 | - | } |
|
| 157 | - | if ackMemo(3, 1) != 13 { |
|
| 158 | - | return 5; |
|
| 159 | - | } |
|
| 160 | - | if ackMemo(3, 2) != 29 { |
|
| 161 | - | return 6; |
|
| 162 | - | } |
|
| 163 | - | if ackMemo(3, 3) != 61 { |
|
| 164 | - | return 7; |
|
| 165 | - | } |
|
| 166 | - | if ackMemo(3, 4) != 125 { |
|
| 167 | - | return 8; |
|
| 168 | - | } |
|
| 124 | + | assert ackMemo(3, 0) == 5; |
|
| 125 | + | assert ackMemo(3, 1) == 13; |
|
| 126 | + | assert ackMemo(3, 2) == 29; |
|
| 127 | + | assert ackMemo(3, 3) == 61; |
|
| 128 | + | assert ackMemo(3, 4) == 125; |
|
| 169 | 129 | // A(3, 5) = 2^8 - 3 = 253 |
|
| 170 | - | if ackMemo(3, 5) != 253 { |
|
| 171 | - | return 9; |
|
| 172 | - | } |
|
| 130 | + | assert ackMemo(3, 5) == 253; |
|
| 173 | 131 | // A(3, 10) = 2^13 - 3 = 8189 |
|
| 174 | - | if ackMemo(3, 10) != 8189 { |
|
| 175 | - | return 10; |
|
| 176 | - | } |
|
| 132 | + | assert ackMemo(3, 10) == 8189; |
|
| 177 | 133 | ||
| 178 | 134 | return 0; |
|
| 179 | 135 | } |
|
| 180 | 136 | ||
| 181 | 137 | /// Cross-check recursive and memoized for small values. |
| 206 | 162 | let mut m: u32 = 0; |
|
| 207 | 163 | while m <= 3 { |
|
| 208 | 164 | let mut n: u32 = 0; |
|
| 209 | 165 | while n < 20 { |
|
| 210 | 166 | let val: i32 = ackMemo(m, n); |
|
| 211 | - | if val <= n as i32 { |
|
| 212 | - | return 1; |
|
| 213 | - | } |
|
| 167 | + | assert val > n as i32; |
|
| 214 | 168 | // A(m, n) < A(m, n+1) (strictly increasing in n). |
|
| 215 | 169 | let valNext: i32 = ackMemo(m, n + 1); |
|
| 216 | - | if valNext <= val { |
|
| 217 | - | return 2; |
|
| 218 | - | } |
|
| 170 | + | assert valNext > val; |
|
| 219 | 171 | n += 1; |
|
| 220 | 172 | } |
|
| 221 | 173 | m += 1; |
|
| 222 | 174 | } |
|
| 223 | 175 |
| 226 | 178 | while m2 < 3 { |
|
| 227 | 179 | let mut n2: u32 = 0; |
|
| 228 | 180 | while n2 < 10 { |
|
| 229 | 181 | let lower: i32 = ackMemo(m2, n2); |
|
| 230 | 182 | let upper: i32 = ackMemo(m2 + 1, n2); |
|
| 231 | - | if upper <= lower { |
|
| 232 | - | return 3; |
|
| 233 | - | } |
|
| 183 | + | assert upper > lower; |
|
| 234 | 184 | n2 += 1; |
|
| 235 | 185 | } |
|
| 236 | 186 | m2 += 1; |
|
| 237 | 187 | } |
|
| 238 | 188 |
lib/std/arch/rv64/tests/prog.bignum.rad
+34 -102
| 185 | 185 | ||
| 186 | 186 | bnFromU32(&mut a[..], 0xFFFFFFFF); |
|
| 187 | 187 | bnFromU32(&mut b[..], 1); |
|
| 188 | 188 | let carry: u32 = bnAdd(&mut c[..], &a[..], &b[..]); |
|
| 189 | 189 | ||
| 190 | - | if carry != 0 { |
|
| 191 | - | return 1; |
|
| 192 | - | } |
|
| 193 | - | if c[0] != 0 { |
|
| 194 | - | return 2; |
|
| 195 | - | } |
|
| 196 | - | if c[1] != 1 { |
|
| 197 | - | return 3; |
|
| 198 | - | } |
|
| 190 | + | assert carry == 0; |
|
| 191 | + | assert c[0] == 0; |
|
| 192 | + | assert c[1] == 1; |
|
| 199 | 193 | ||
| 200 | 194 | bnFromU32(&mut b[..], 0xFFFFFFFF); |
|
| 201 | 195 | let carry2: u32 = bnAdd(&mut d[..], &c[..], &b[..]); |
|
| 202 | - | if carry2 != 0 { |
|
| 203 | - | return 4; |
|
| 204 | - | } |
|
| 205 | - | if d[0] != 0xFFFFFFFF { |
|
| 206 | - | return 5; |
|
| 207 | - | } |
|
| 208 | - | if d[1] != 1 { |
|
| 209 | - | return 6; |
|
| 210 | - | } |
|
| 196 | + | assert carry2 == 0; |
|
| 197 | + | assert d[0] == 0xFFFFFFFF; |
|
| 198 | + | assert d[1] == 1; |
|
| 211 | 199 | ||
| 212 | 200 | return 0; |
|
| 213 | 201 | } |
|
| 214 | 202 | ||
| 215 | 203 | /// Test subtraction. |
| 221 | 209 | bnZero(&mut a[..]); |
|
| 222 | 210 | a[1] = 1; |
|
| 223 | 211 | bnFromU32(&mut b[..], 1); |
|
| 224 | 212 | let borrow: u32 = bnSub(&mut c[..], &a[..], &b[..]); |
|
| 225 | 213 | ||
| 226 | - | if borrow != 0 { |
|
| 227 | - | return 1; |
|
| 228 | - | } |
|
| 229 | - | if c[0] != 0xFFFFFFFF { |
|
| 230 | - | return 2; |
|
| 231 | - | } |
|
| 232 | - | if c[1] != 0 { |
|
| 233 | - | return 3; |
|
| 234 | - | } |
|
| 214 | + | assert borrow == 0; |
|
| 215 | + | assert c[0] == 0xFFFFFFFF; |
|
| 216 | + | assert c[1] == 0; |
|
| 235 | 217 | ||
| 236 | 218 | return 0; |
|
| 237 | 219 | } |
|
| 238 | 220 | ||
| 239 | 221 | /// Test multiplication. |
| 244 | 226 | ||
| 245 | 227 | bnFromU32(&mut a[..], 12345); |
|
| 246 | 228 | bnFromU32(&mut b[..], 67890); |
|
| 247 | 229 | bnMul(&mut wide[..], &a[..], &b[..]); |
|
| 248 | 230 | ||
| 249 | - | if wide[0] != 838102050 { |
|
| 250 | - | return 1; |
|
| 251 | - | } |
|
| 252 | - | if wide[1] != 0 { |
|
| 253 | - | return 2; |
|
| 254 | - | } |
|
| 231 | + | assert wide[0] == 838102050; |
|
| 232 | + | assert wide[1] == 0; |
|
| 255 | 233 | ||
| 256 | 234 | bnFromU32(&mut a[..], 0xFFFFFFFF); |
|
| 257 | 235 | bnFromU32(&mut b[..], 0xFFFFFFFF); |
|
| 258 | 236 | bnMul(&mut wide[..], &a[..], &b[..]); |
|
| 259 | 237 | ||
| 260 | - | if wide[0] != 0x00000001 { |
|
| 261 | - | return 3; |
|
| 262 | - | } |
|
| 263 | - | if wide[1] != 0xFFFFFFFE { |
|
| 264 | - | return 4; |
|
| 265 | - | } |
|
| 238 | + | assert wide[0] == 0x00000001; |
|
| 239 | + | assert wide[1] == 0xFFFFFFFE; |
|
| 266 | 240 | ||
| 267 | 241 | return 0; |
|
| 268 | 242 | } |
|
| 269 | 243 | ||
| 270 | 244 | /// Test the identity a + b - b = a. |
| 285 | 259 | b[3] = 0x00AABB00; |
|
| 286 | 260 | ||
| 287 | 261 | bnAdd(&mut c[..], &a[..], &b[..]); |
|
| 288 | 262 | bnSub(&mut d[..], &c[..], &b[..]); |
|
| 289 | 263 | ||
| 290 | - | if bnCmp(&d[..], &a[..]) != 0 { |
|
| 291 | - | return 1; |
|
| 292 | - | } |
|
| 264 | + | assert bnCmp(&d[..], &a[..]) == 0; |
|
| 293 | 265 | ||
| 294 | 266 | bnSub(&mut d[..], &c[..], &a[..]); |
|
| 295 | - | if bnCmp(&d[..], &b[..]) != 0 { |
|
| 296 | - | return 2; |
|
| 297 | - | } |
|
| 267 | + | assert bnCmp(&d[..], &b[..]) == 0; |
|
| 298 | 268 | ||
| 299 | 269 | return 0; |
|
| 300 | 270 | } |
|
| 301 | 271 | ||
| 302 | 272 | /// Test shift operations. |
| 305 | 275 | let mut b: [u32; 4] = [0; 4]; |
|
| 306 | 276 | let mut c: [u32; 4] = [0; 4]; |
|
| 307 | 277 | ||
| 308 | 278 | bnFromU32(&mut a[..], 1); |
|
| 309 | 279 | bnShl1(&mut b[..], &a[..]); |
|
| 310 | - | if b[0] != 2 { |
|
| 311 | - | return 1; |
|
| 312 | - | } |
|
| 280 | + | assert b[0] == 2; |
|
| 313 | 281 | ||
| 314 | 282 | bnFromU32(&mut a[..], 0x80000000); |
|
| 315 | 283 | bnShl1(&mut b[..], &a[..]); |
|
| 316 | - | if b[0] != 0 { |
|
| 317 | - | return 2; |
|
| 318 | - | } |
|
| 319 | - | if b[1] != 1 { |
|
| 320 | - | return 3; |
|
| 321 | - | } |
|
| 284 | + | assert b[0] == 0; |
|
| 285 | + | assert b[1] == 1; |
|
| 322 | 286 | ||
| 323 | 287 | bnShr1(&mut c[..], &b[..]); |
|
| 324 | - | if c[0] != 0x80000000 { |
|
| 325 | - | return 4; |
|
| 326 | - | } |
|
| 327 | - | if c[1] != 0 { |
|
| 328 | - | return 5; |
|
| 329 | - | } |
|
| 288 | + | assert c[0] == 0x80000000; |
|
| 289 | + | assert c[1] == 0; |
|
| 330 | 290 | ||
| 331 | 291 | return 0; |
|
| 332 | 292 | } |
|
| 333 | 293 | ||
| 334 | 294 | /// Test large multiply. |
| 342 | 302 | a[2] = 0; |
|
| 343 | 303 | a[3] = 0; |
|
| 344 | 304 | ||
| 345 | 305 | bnFromU32(&mut b[..], 1); |
|
| 346 | 306 | bnMul(&mut wide[..], &a[..], &b[..]); |
|
| 347 | - | if wide[0] != 0xFFFFFFFF { |
|
| 348 | - | return 1; |
|
| 349 | - | } |
|
| 350 | - | if wide[1] != 0xFFFFFFFF { |
|
| 351 | - | return 2; |
|
| 352 | - | } |
|
| 353 | - | if wide[2] != 0 { |
|
| 354 | - | return 3; |
|
| 355 | - | } |
|
| 307 | + | assert wide[0] == 0xFFFFFFFF; |
|
| 308 | + | assert wide[1] == 0xFFFFFFFF; |
|
| 309 | + | assert wide[2] == 0; |
|
| 356 | 310 | ||
| 357 | 311 | bnZero(&mut a[..]); |
|
| 358 | 312 | a[1] = 1; |
|
| 359 | 313 | bnZero(&mut b[..]); |
|
| 360 | 314 | b[1] = 1; |
|
| 361 | 315 | bnMul(&mut wide[..], &a[..], &b[..]); |
|
| 362 | - | if wide[0] != 0 { |
|
| 363 | - | return 4; |
|
| 364 | - | } |
|
| 365 | - | if wide[1] != 0 { |
|
| 366 | - | return 5; |
|
| 367 | - | } |
|
| 368 | - | if wide[2] != 1 { |
|
| 369 | - | return 6; |
|
| 370 | - | } |
|
| 371 | - | if wide[3] != 0 { |
|
| 372 | - | return 7; |
|
| 373 | - | } |
|
| 316 | + | assert wide[0] == 0; |
|
| 317 | + | assert wide[1] == 0; |
|
| 318 | + | assert wide[2] == 1; |
|
| 319 | + | assert wide[3] == 0; |
|
| 374 | 320 | ||
| 375 | 321 | return 0; |
|
| 376 | 322 | } |
|
| 377 | 323 | ||
| 378 | 324 | /// Test Fibonacci sequence with big numbers. |
| 390 | 336 | bnCopy(&mut fibA[..], &fibB[..]); |
|
| 391 | 337 | bnCopy(&mut fibB[..], &fibC[..]); |
|
| 392 | 338 | i += 1; |
|
| 393 | 339 | } |
|
| 394 | 340 | ||
| 395 | - | if fibB[0] != 0x1E8D0A40 { |
|
| 396 | - | return 1; |
|
| 397 | - | } |
|
| 398 | - | if fibB[1] != 0x01 { |
|
| 399 | - | return 2; |
|
| 400 | - | } |
|
| 341 | + | assert fibB[0] == 0x1E8D0A40; |
|
| 342 | + | assert fibB[1] == 0x01; |
|
| 401 | 343 | ||
| 402 | 344 | let mut fa: [u32; 4] = [0; 4]; |
|
| 403 | 345 | let mut fb: [u32; 4] = [0; 4]; |
|
| 404 | 346 | let mut fc: [u32; 4] = [0; 4]; |
|
| 405 | 347 | fa[0] = 0; |
| 410 | 352 | bnCopy(&mut fa[..], &fb[..]); |
|
| 411 | 353 | bnCopy(&mut fb[..], &fc[..]); |
|
| 412 | 354 | i += 1; |
|
| 413 | 355 | } |
|
| 414 | 356 | bnAdd(&mut fc[..], &fa[..], &fb[..]); |
|
| 415 | - | if bnCmp(&fc[..], &fibB[..]) != 0 { |
|
| 416 | - | return 3; |
|
| 417 | - | } |
|
| 357 | + | assert bnCmp(&fc[..], &fibB[..]) == 0; |
|
| 418 | 358 | ||
| 419 | 359 | return 0; |
|
| 420 | 360 | } |
|
| 421 | 361 | ||
| 422 | 362 | /// Test compare function. |
| 425 | 365 | let mut b: [u32; 4] = [0; 4]; |
|
| 426 | 366 | ||
| 427 | 367 | bnFromU32(&mut a[..], 100); |
|
| 428 | 368 | bnFromU32(&mut b[..], 200); |
|
| 429 | 369 | ||
| 430 | - | if bnCmp(&a[..], &b[..]) != -1 { |
|
| 431 | - | return 1; |
|
| 432 | - | } |
|
| 433 | - | if bnCmp(&b[..], &a[..]) != 1 { |
|
| 434 | - | return 2; |
|
| 435 | - | } |
|
| 436 | - | if bnCmp(&a[..], &a[..]) != 0 { |
|
| 437 | - | return 3; |
|
| 438 | - | } |
|
| 370 | + | assert bnCmp(&a[..], &b[..]) == -1; |
|
| 371 | + | assert bnCmp(&b[..], &a[..]) == 1; |
|
| 372 | + | assert bnCmp(&a[..], &a[..]) == 0; |
|
| 439 | 373 | ||
| 440 | 374 | bnZero(&mut a[..]); |
|
| 441 | 375 | bnZero(&mut b[..]); |
|
| 442 | 376 | a[3] = 1; |
|
| 443 | 377 | b[0] = 0xFFFFFFFF; |
|
| 444 | 378 | b[1] = 0xFFFFFFFF; |
|
| 445 | 379 | b[2] = 0xFFFFFFFF; |
|
| 446 | - | if bnCmp(&a[..], &b[..]) != 1 { |
|
| 447 | - | return 4; |
|
| 448 | - | } |
|
| 380 | + | assert bnCmp(&a[..], &b[..]) == 1; |
|
| 449 | 381 | ||
| 450 | 382 | return 0; |
|
| 451 | 383 | } |
|
| 452 | 384 | ||
| 453 | 385 | @default fn main() -> i32 { |
lib/std/arch/rv64/tests/prog.binsearch.rad
+10 -30
| 25 | 25 | fn testPresent(data: *[i32]) -> i32 { |
|
| 26 | 26 | // First element. |
|
| 27 | 27 | let idx0 = binarySearch(data, 3) else { |
|
| 28 | 28 | return 1; |
|
| 29 | 29 | }; |
|
| 30 | - | if idx0 != 0 { |
|
| 31 | - | return 1; |
|
| 32 | - | } |
|
| 30 | + | assert idx0 == 0; |
|
| 33 | 31 | ||
| 34 | 32 | // Last element. |
|
| 35 | 33 | let idx19 = binarySearch(data, 120) else { |
|
| 36 | 34 | return 2; |
|
| 37 | 35 | }; |
|
| 38 | - | if idx19 != 19 { |
|
| 39 | - | return 2; |
|
| 40 | - | } |
|
| 36 | + | assert idx19 == 19; |
|
| 41 | 37 | ||
| 42 | 38 | // Middle element. |
|
| 43 | 39 | let idx9 = binarySearch(data, 58) else { |
|
| 44 | 40 | return 3; |
|
| 45 | 41 | }; |
|
| 46 | - | if idx9 != 9 { |
|
| 47 | - | return 3; |
|
| 48 | - | } |
|
| 42 | + | assert idx9 == 9; |
|
| 49 | 43 | ||
| 50 | 44 | // Another element. |
|
| 51 | 45 | if let idx = binarySearch(data, 22) { |
|
| 52 | - | if idx != 4 { |
|
| 53 | - | return 4; |
|
| 54 | - | } |
|
| 46 | + | assert idx == 4; |
|
| 55 | 47 | } else { |
|
| 56 | 48 | return 4; |
|
| 57 | 49 | } |
|
| 58 | 50 | ||
| 59 | 51 | // Element near end. |
|
| 60 | 52 | let idx16 = binarySearch(data, 100) else { |
|
| 61 | 53 | return 5; |
|
| 62 | 54 | }; |
|
| 63 | - | if idx16 != 16 { |
|
| 64 | - | return 5; |
|
| 65 | - | } |
|
| 55 | + | assert idx16 == 16; |
|
| 66 | 56 | return 0; |
|
| 67 | 57 | } |
|
| 68 | 58 | ||
| 69 | 59 | /// Test searching for elements that do not exist. |
|
| 70 | 60 | fn testAbsent(data: *[i32]) -> i32 { |
|
| 71 | 61 | // Below range. |
|
| 72 | - | if binarySearch(data, 1) != nil { |
|
| 73 | - | return 1; |
|
| 74 | - | } |
|
| 62 | + | assert binarySearch(data, 1) == nil; |
|
| 75 | 63 | // Above range. |
|
| 76 | - | if binarySearch(data, 200) != nil { |
|
| 77 | - | return 2; |
|
| 78 | - | } |
|
| 64 | + | assert binarySearch(data, 200) == nil; |
|
| 79 | 65 | // Between existing elements. |
|
| 80 | - | if binarySearch(data, 40) != nil { |
|
| 81 | - | return 3; |
|
| 82 | - | } |
|
| 66 | + | assert binarySearch(data, 40) == nil; |
|
| 83 | 67 | // Just above an existing element. |
|
| 84 | - | if binarySearch(data, 8) != nil { |
|
| 85 | - | return 4; |
|
| 86 | - | } |
|
| 68 | + | assert binarySearch(data, 8) == nil; |
|
| 87 | 69 | // Just below an existing element. |
|
| 88 | - | if binarySearch(data, 99) != nil { |
|
| 89 | - | return 5; |
|
| 90 | - | } |
|
| 70 | + | assert binarySearch(data, 99) == nil; |
|
| 91 | 71 | return 0; |
|
| 92 | 72 | } |
|
| 93 | 73 | ||
| 94 | 74 | /// Test searching for every element in the array. |
|
| 95 | 75 | fn testAllPresent(data: *[i32]) -> i32 { |
lib/std/arch/rv64/tests/prog.bubblesort.rad
+8 -24
| 48 | 48 | } |
|
| 49 | 49 | ||
| 50 | 50 | /// Verify specific positions in the sorted output. |
|
| 51 | 51 | fn verifyPositions(data: *[i32]) -> i32 { |
|
| 52 | 52 | // Sorted: 3 5 7 12 17 19 28 31 42 50 55 66 71 80 88 93 |
|
| 53 | - | if data[0] != 3 { |
|
| 54 | - | return 1; |
|
| 55 | - | } |
|
| 56 | - | if data[1] != 5 { |
|
| 57 | - | return 2; |
|
| 58 | - | } |
|
| 59 | - | if data[2] != 7 { |
|
| 60 | - | return 3; |
|
| 61 | - | } |
|
| 62 | - | if data[7] != 31 { |
|
| 63 | - | return 4; |
|
| 64 | - | } |
|
| 65 | - | if data[14] != 88 { |
|
| 66 | - | return 5; |
|
| 67 | - | } |
|
| 68 | - | if data[15] != 93 { |
|
| 69 | - | return 6; |
|
| 70 | - | } |
|
| 53 | + | assert data[0] == 3; |
|
| 54 | + | assert data[1] == 5; |
|
| 55 | + | assert data[2] == 7; |
|
| 56 | + | assert data[7] == 31; |
|
| 57 | + | assert data[14] == 88; |
|
| 58 | + | assert data[15] == 93; |
|
| 71 | 59 | return 0; |
|
| 72 | 60 | } |
|
| 73 | 61 | ||
| 74 | 62 | @default fn main() -> i32 { |
|
| 75 | 63 | let mut data: [i32; 16] = [ |
| 81 | 69 | let sumBefore = sum(&data[..]); |
|
| 82 | 70 | ||
| 83 | 71 | bubbleSort(&mut data[..]); |
|
| 84 | 72 | ||
| 85 | 73 | // Check the array is sorted. |
|
| 86 | - | if not isSorted(&data[..]) { |
|
| 87 | - | return 1; |
|
| 88 | - | } |
|
| 74 | + | assert isSorted(&data[..]); |
|
| 89 | 75 | ||
| 90 | 76 | // Check sum is preserved (no data corruption). |
|
| 91 | 77 | let sumAfter = sum(&data[..]); |
|
| 92 | - | if sumBefore != sumAfter { |
|
| 93 | - | return 2; |
|
| 94 | - | } |
|
| 78 | + | assert sumBefore == sumAfter; |
|
| 95 | 79 | ||
| 96 | 80 | // Check specific element positions. |
|
| 97 | 81 | let r = verifyPositions(&data[..]); |
|
| 98 | 82 | if r != 0 { |
|
| 99 | 83 | return 10 + r; |
lib/std/arch/rv64/tests/prog.cordic.rad
+11 -33
| 126 | 126 | // cos(0) should be close to 65536 (1.0 in Q16.16). |
|
| 127 | 127 | let cosErr: i32 = abs(r.cos - SCALE); |
|
| 128 | 128 | let sinErr: i32 = abs(r.sin); |
|
| 129 | 129 | ||
| 130 | 130 | // Allow error of ~1% = 655. |
|
| 131 | - | if cosErr > 655 { |
|
| 132 | - | return 1; |
|
| 133 | - | } |
|
| 134 | - | if sinErr > 655 { |
|
| 135 | - | return 2; |
|
| 136 | - | } |
|
| 131 | + | assert cosErr <= 655; |
|
| 132 | + | assert sinErr <= 655; |
|
| 137 | 133 | return 0; |
|
| 138 | 134 | } |
|
| 139 | 135 | ||
| 140 | 136 | /// Test cos(pi/2) = 0, sin(pi/2) = 1. |
|
| 141 | 137 | fn testHalfPi(atanTable: *[i32]) -> i32 { |
|
| 142 | 138 | let r: CosSin = cosSin(HALF_PI, atanTable); |
|
| 143 | 139 | let cosErr: i32 = abs(r.cos); |
|
| 144 | 140 | let sinErr: i32 = abs(r.sin - SCALE); |
|
| 145 | 141 | ||
| 146 | - | if cosErr > 655 { |
|
| 147 | - | return 1; |
|
| 148 | - | } |
|
| 149 | - | if sinErr > 655 { |
|
| 150 | - | return 2; |
|
| 151 | - | } |
|
| 142 | + | assert cosErr <= 655; |
|
| 143 | + | assert sinErr <= 655; |
|
| 152 | 144 | return 0; |
|
| 153 | 145 | } |
|
| 154 | 146 | ||
| 155 | 147 | /// Test cos(pi) = -1, sin(pi) = 0. |
|
| 156 | 148 | fn testPi(atanTable: *[i32]) -> i32 { |
|
| 157 | 149 | let r: CosSin = cosSin(PI, atanTable); |
|
| 158 | 150 | let cosErr: i32 = abs(r.cos + SCALE); |
|
| 159 | 151 | let sinErr: i32 = abs(r.sin); |
|
| 160 | 152 | ||
| 161 | - | if cosErr > 655 { |
|
| 162 | - | return 1; |
|
| 163 | - | } |
|
| 164 | - | if sinErr > 655 { |
|
| 165 | - | return 2; |
|
| 166 | - | } |
|
| 153 | + | assert cosErr <= 655; |
|
| 154 | + | assert sinErr <= 655; |
|
| 167 | 155 | return 0; |
|
| 168 | 156 | } |
|
| 169 | 157 | ||
| 170 | 158 | /// Test Pythagorean identity: sin^2 + cos^2 = 1 for several angles. |
|
| 171 | 159 | fn testPythagorean(atanTable: *[i32]) -> i32 { |
| 180 | 168 | let cos2: i32 = fpmul(r.cos, r.cos); |
|
| 181 | 169 | let sum: i32 = sin2 + cos2; |
|
| 182 | 170 | let err: i32 = abs(sum - SCALE); |
|
| 183 | 171 | ||
| 184 | 172 | // Allow ~2% error due to fixed-point precision. |
|
| 185 | - | if err > 1311 { |
|
| 186 | - | return 1; |
|
| 187 | - | } |
|
| 173 | + | assert err <= 1311; |
|
| 188 | 174 | i += step; |
|
| 189 | 175 | } |
|
| 190 | 176 | return 0; |
|
| 191 | 177 | } |
|
| 192 | 178 |
| 200 | 186 | ||
| 201 | 187 | let rPos: CosSin = cosSin(a, atanTable); |
|
| 202 | 188 | let rNeg: CosSin = cosSin(0 - a, atanTable); |
|
| 203 | 189 | ||
| 204 | 190 | // cos(-x) should equal cos(x). |
|
| 205 | - | if abs(rPos.cos - rNeg.cos) > 655 { |
|
| 206 | - | return 1; |
|
| 207 | - | } |
|
| 191 | + | assert abs(rPos.cos - rNeg.cos) <= 655; |
|
| 208 | 192 | // sin(-x) should equal -sin(x). |
|
| 209 | - | if abs(rPos.sin + rNeg.sin) > 655 { |
|
| 210 | - | return 2; |
|
| 211 | - | } |
|
| 193 | + | assert abs(rPos.sin + rNeg.sin) <= 655; |
|
| 212 | 194 | i += 1; |
|
| 213 | 195 | } |
|
| 214 | 196 | return 0; |
|
| 215 | 197 | } |
|
| 216 | 198 |
| 224 | 206 | let cosErr: i32 = abs(r.cos - 32768); |
|
| 225 | 207 | // sin(pi/3) = 0.866 = 56756 in Q16.16. |
|
| 226 | 208 | let sinErr: i32 = abs(r.sin - 56756); |
|
| 227 | 209 | ||
| 228 | 210 | // Allow ~2% error. |
|
| 229 | - | if cosErr > 1311 { |
|
| 230 | - | return 1; |
|
| 231 | - | } |
|
| 232 | - | if sinErr > 1311 { |
|
| 233 | - | return 2; |
|
| 234 | - | } |
|
| 211 | + | assert cosErr <= 1311; |
|
| 212 | + | assert sinErr <= 1311; |
|
| 235 | 213 | return 0; |
|
| 236 | 214 | } |
|
| 237 | 215 | ||
| 238 | 216 | @default fn main() -> i32 { |
|
| 239 | 217 | /// CORDIC arctangent table in Q16.16 fixed-point. |
lib/std/arch/rv64/tests/prog.crc32.rad
+9 -27
| 35 | 35 | } |
|
| 36 | 36 | ||
| 37 | 37 | /// Test the lookup table has been built correctly. |
|
| 38 | 38 | fn testTable(table: *[u32]) -> i32 { |
|
| 39 | 39 | // TABLE[0] should be 0 (zero input, all shifts produce zero). |
|
| 40 | - | if table[0] != 0 { |
|
| 41 | - | return 1; |
|
| 42 | - | } |
|
| 40 | + | assert table[0] == 0; |
|
| 43 | 41 | // Known value: TABLE[1] = 0x77073096 |
|
| 44 | - | if table[1] != 0x77073096 { |
|
| 45 | - | return 2; |
|
| 46 | - | } |
|
| 42 | + | assert table[1] == 0x77073096; |
|
| 47 | 43 | // TABLE[255] is a known value: 0x2D02EF8D |
|
| 48 | - | if table[255] != 0x2D02EF8D { |
|
| 49 | - | return 3; |
|
| 50 | - | } |
|
| 44 | + | assert table[255] == 0x2D02EF8D; |
|
| 51 | 45 | return 0; |
|
| 52 | 46 | } |
|
| 53 | 47 | ||
| 54 | 48 | /// Test CRC-32 of known strings. |
|
| 55 | 49 | fn testKnownCRC(table: *[u32]) -> i32 { |
|
| 56 | 50 | // CRC-32 of empty data should be 0x00000000. |
|
| 57 | - | if crc32(table, &[]) != 0x00000000 { |
|
| 58 | - | return 1; |
|
| 59 | - | } |
|
| 51 | + | assert crc32(table, &[]) == 0x00000000; |
|
| 60 | 52 | ||
| 61 | 53 | // CRC-32 of "123456789" = 0xCBF43926 (the standard check value). |
|
| 62 | 54 | let check: [u8; 9] = [0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39]; |
|
| 63 | - | if crc32(table, &check[..]) != 0xCBF43926 { |
|
| 64 | - | return 2; |
|
| 65 | - | } |
|
| 55 | + | assert crc32(table, &check[..]) == 0xCBF43926; |
|
| 66 | 56 | ||
| 67 | 57 | // CRC-32 of a single byte 'A' (0x41) = 0xD3D99E8B. |
|
| 68 | 58 | let single: [u8; 1] = [0x41]; |
|
| 69 | - | if crc32(table, &single[..]) != 0xD3D99E8B { |
|
| 70 | - | return 3; |
|
| 71 | - | } |
|
| 59 | + | assert crc32(table, &single[..]) == 0xD3D99E8B; |
|
| 72 | 60 | return 0; |
|
| 73 | 61 | } |
|
| 74 | 62 | ||
| 75 | 63 | /// Test CRC-32 of incrementally built data. |
|
| 76 | 64 | fn testIncremental(table: *[u32]) -> i32 { |
| 82 | 70 | i += 1; |
|
| 83 | 71 | } |
|
| 84 | 72 | let crcFull = crc32(table, &buf[..]); |
|
| 85 | 73 | ||
| 86 | 74 | // CRC should be non-zero and deterministic. |
|
| 87 | - | if crcFull == 0 { |
|
| 88 | - | return 1; |
|
| 89 | - | } |
|
| 75 | + | assert crcFull != 0; |
|
| 90 | 76 | ||
| 91 | 77 | // Recompute and verify it's the same. |
|
| 92 | - | if crc32(table, &buf[..]) != crcFull { |
|
| 93 | - | return 2; |
|
| 94 | - | } |
|
| 78 | + | assert crc32(table, &buf[..]) == crcFull; |
|
| 95 | 79 | ||
| 96 | 80 | // Known value for bytes 0..31: 0x91267E8A |
|
| 97 | - | if crcFull != 0x91267E8A { |
|
| 98 | - | return 3; |
|
| 99 | - | } |
|
| 81 | + | assert crcFull == 0x91267E8A; |
|
| 100 | 82 | return 0; |
|
| 101 | 83 | } |
|
| 102 | 84 | ||
| 103 | 85 | @default fn main() -> i32 { |
|
| 104 | 86 | let mut table: [u32; 256] = [0; 256]; |
lib/std/arch/rv64/tests/prog.dijkstra.rad
+15 -45
| 187 | 187 | } |
|
| 188 | 188 | } |
|
| 189 | 189 | ||
| 190 | 190 | let mut path: [u32; 16] = [0; 16]; |
|
| 191 | 191 | let len: u32 = reconstructPath(g, 4, &mut path[..]); |
|
| 192 | - | if len != 5 { |
|
| 193 | - | return 6; |
|
| 194 | - | } |
|
| 195 | - | if path[0] != 0 { |
|
| 196 | - | return 7; |
|
| 197 | - | } |
|
| 198 | - | if path[4] != 4 { |
|
| 199 | - | return 8; |
|
| 200 | - | } |
|
| 192 | + | assert len == 5; |
|
| 193 | + | assert path[0] == 0; |
|
| 194 | + | assert path[4] == 4; |
|
| 201 | 195 | ||
| 202 | 196 | return 0; |
|
| 203 | 197 | } |
|
| 204 | 198 | ||
| 205 | 199 | fn testShortcut(g: *mut Graph) -> i32 { |
| 209 | 203 | addEdge(g, 0, 3, 5); |
|
| 210 | 204 | addEdge(g, 3, 2, 3); |
|
| 211 | 205 | ||
| 212 | 206 | dijkstra(g, 0); |
|
| 213 | 207 | ||
| 214 | - | if g.dist[2] != 8 { |
|
| 215 | - | return 1; |
|
| 216 | - | } |
|
| 208 | + | assert g.dist[2] == 8; |
|
| 217 | 209 | ||
| 218 | 210 | let prev2 = getPrev(g, 2) else { |
|
| 219 | 211 | return 2; |
|
| 220 | 212 | }; |
|
| 221 | - | if prev2 != 3 { |
|
| 222 | - | return 2; |
|
| 223 | - | } |
|
| 213 | + | assert prev2 == 3; |
|
| 224 | 214 | ||
| 225 | 215 | return 0; |
|
| 226 | 216 | } |
|
| 227 | 217 | ||
| 228 | 218 | fn testBidirectional(g: *mut Graph) -> i32 { |
| 287 | 277 | addEdge(g, 3, 4, 2); |
|
| 288 | 278 | addEdge(g, 4, 5, 1); |
|
| 289 | 279 | ||
| 290 | 280 | dijkstra(g, 0); |
|
| 291 | 281 | ||
| 292 | - | if g.dist[0] != 0 { |
|
| 293 | - | return 1; |
|
| 294 | - | } |
|
| 295 | - | if g.dist[1] != 5 { |
|
| 296 | - | return 2; |
|
| 297 | - | } |
|
| 298 | - | if g.dist[2] != 8 { |
|
| 299 | - | return 3; |
|
| 300 | - | } |
|
| 282 | + | assert g.dist[0] == 0; |
|
| 283 | + | assert g.dist[1] == 5; |
|
| 284 | + | assert g.dist[2] == 8; |
|
| 301 | 285 | // Unreachable nodes stay at INF. |
|
| 302 | - | if g.dist[3] != INF { |
|
| 303 | - | return 4; |
|
| 304 | - | } |
|
| 305 | - | if g.dist[4] != INF { |
|
| 306 | - | return 5; |
|
| 307 | - | } |
|
| 308 | - | if g.dist[5] != INF { |
|
| 309 | - | return 6; |
|
| 310 | - | } |
|
| 286 | + | assert g.dist[3] == INF; |
|
| 287 | + | assert g.dist[4] == INF; |
|
| 288 | + | assert g.dist[5] == INF; |
|
| 311 | 289 | ||
| 312 | 290 | // Predecessors of unreachable nodes should be nil. |
|
| 313 | - | if getPrev(g, 3) != nil { |
|
| 314 | - | return 7; |
|
| 315 | - | } |
|
| 291 | + | assert getPrev(g, 3) == nil; |
|
| 316 | 292 | ||
| 317 | 293 | return 0; |
|
| 318 | 294 | } |
|
| 319 | 295 | ||
| 320 | 296 | fn testDiamond(g: *mut Graph) -> i32 { |
| 325 | 301 | addEdge(g, 2, 3, 5); |
|
| 326 | 302 | addEdge(g, 3, 4, 2); |
|
| 327 | 303 | ||
| 328 | 304 | dijkstra(g, 0); |
|
| 329 | 305 | ||
| 330 | - | if g.dist[3] != 10 { |
|
| 331 | - | return 1; |
|
| 332 | - | } |
|
| 333 | - | if g.dist[4] != 12 { |
|
| 334 | - | return 2; |
|
| 335 | - | } |
|
| 306 | + | assert g.dist[3] == 10; |
|
| 307 | + | assert g.dist[4] == 12; |
|
| 336 | 308 | // Predecessor should be 1 or 2. |
|
| 337 | 309 | let prev3 = getPrev(g, 3) else { |
|
| 338 | 310 | return 3; |
|
| 339 | 311 | }; |
|
| 340 | - | if prev3 != 1 and prev3 != 2 { |
|
| 341 | - | return 3; |
|
| 342 | - | } |
|
| 312 | + | assert prev3 == 1 or prev3 == 2; |
|
| 343 | 313 | ||
| 344 | 314 | return 0; |
|
| 345 | 315 | } |
|
| 346 | 316 | ||
| 347 | 317 | @default fn main() -> i32 { |
lib/std/arch/rv64/tests/prog.eval.rad
+10 -30
| 126 | 126 | ||
| 127 | 127 | /// Test 1: Simple addition: 3 + 4 = 7 |
|
| 128 | 128 | fn testSimpleAdd(pool: *mut Pool) -> i32 { |
|
| 129 | 129 | reset(pool); |
|
| 130 | 130 | let root = add(pool, num(pool, 3), num(pool, 4)); |
|
| 131 | - | if try! eval(&pool.nodes[..], root) != 7 { |
|
| 132 | - | return 1; |
|
| 133 | - | } |
|
| 131 | + | assert try! eval(&pool.nodes[..], root) == 7; |
|
| 134 | 132 | return 0; |
|
| 135 | 133 | } |
|
| 136 | 134 | ||
| 137 | 135 | /// Test 2: Nested expression: (2 + 3) * (4 - 1) = 5 * 3 = 15 |
|
| 138 | 136 | fn testNested(pool: *mut Pool) -> i32 { |
|
| 139 | 137 | reset(pool); |
|
| 140 | 138 | let left = add(pool, num(pool, 2), num(pool, 3)); |
|
| 141 | 139 | let right = sub(pool, num(pool, 4), num(pool, 1)); |
|
| 142 | 140 | let root = mul(pool, left, right); |
|
| 143 | - | if try! eval(&pool.nodes[..], root) != 15 { |
|
| 144 | - | return 1; |
|
| 145 | - | } |
|
| 146 | - | if countNodes(&pool.nodes[..], root) != 7 { |
|
| 147 | - | return 2; |
|
| 148 | - | } |
|
| 141 | + | assert try! eval(&pool.nodes[..], root) == 15; |
|
| 142 | + | assert countNodes(&pool.nodes[..], root) == 7; |
|
| 149 | 143 | return 0; |
|
| 150 | 144 | } |
|
| 151 | 145 | ||
| 152 | 146 | /// Test 3: Complex expression: ((10 + 5) * 2 - 6) / 4 = (30 - 6) / 4 = 24 / 4 = 6 |
|
| 153 | 147 | fn testComplex(pool: *mut Pool) -> i32 { |
|
| 154 | 148 | reset(pool); |
|
| 155 | 149 | let a = add(pool, num(pool, 10), num(pool, 5)); |
|
| 156 | 150 | let b = mul(pool, a, num(pool, 2)); |
|
| 157 | 151 | let c = sub(pool, b, num(pool, 6)); |
|
| 158 | 152 | let root = div(pool, c, num(pool, 4)); |
|
| 159 | - | if try! eval(&pool.nodes[..], root) != 6 { |
|
| 160 | - | return 1; |
|
| 161 | - | } |
|
| 153 | + | assert try! eval(&pool.nodes[..], root) == 6; |
|
| 162 | 154 | return 0; |
|
| 163 | 155 | } |
|
| 164 | 156 | ||
| 165 | 157 | /// Test 4: Negation: -(3 + 4) = -7 |
|
| 166 | 158 | fn testNeg(pool: *mut Pool) -> i32 { |
|
| 167 | 159 | reset(pool); |
|
| 168 | 160 | let root = neg(pool, add(pool, num(pool, 3), num(pool, 4))); |
|
| 169 | - | if try! eval(&pool.nodes[..], root) != -7 { |
|
| 170 | - | return 1; |
|
| 171 | - | } |
|
| 161 | + | assert try! eval(&pool.nodes[..], root) == -7; |
|
| 172 | 162 | return 0; |
|
| 173 | 163 | } |
|
| 174 | 164 | ||
| 175 | 165 | /// Test 5: Deep tree: 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 = 36 |
|
| 176 | 166 | fn testDeep(pool: *mut Pool) -> i32 { |
| 178 | 168 | let mut root = num(pool, 1); |
|
| 179 | 169 | let values: [i32; 7] = [2, 3, 4, 5, 6, 7, 8]; |
|
| 180 | 170 | for v in values { |
|
| 181 | 171 | root = add(pool, root, num(pool, v)); |
|
| 182 | 172 | } |
|
| 183 | - | if try! eval(&pool.nodes[..], root) != 36 { |
|
| 184 | - | return 1; |
|
| 185 | - | } |
|
| 186 | - | if countNodes(&pool.nodes[..], root) != 15 { |
|
| 187 | - | return 2; |
|
| 188 | - | } |
|
| 173 | + | assert try! eval(&pool.nodes[..], root) == 36; |
|
| 174 | + | assert countNodes(&pool.nodes[..], root) == 15; |
|
| 189 | 175 | return 0; |
|
| 190 | 176 | } |
|
| 191 | 177 | ||
| 192 | 178 | /// Test 6: Mixed operations: (100 - 3 * (2 + 8)) / 7 = (100 - 30) / 7 = 70 / 7 = 10 |
|
| 193 | 179 | fn testMixed(pool: *mut Pool) -> i32 { |
|
| 194 | 180 | reset(pool); |
|
| 195 | 181 | let inner = add(pool, num(pool, 2), num(pool, 8)); |
|
| 196 | 182 | let product = mul(pool, num(pool, 3), inner); |
|
| 197 | 183 | let diff = sub(pool, num(pool, 100), product); |
|
| 198 | 184 | let root = div(pool, diff, num(pool, 7)); |
|
| 199 | - | if try! eval(&pool.nodes[..], root) != 10 { |
|
| 200 | - | return 1; |
|
| 201 | - | } |
|
| 185 | + | assert try! eval(&pool.nodes[..], root) == 10; |
|
| 202 | 186 | return 0; |
|
| 203 | 187 | } |
|
| 204 | 188 | ||
| 205 | 189 | /// Test 7: Single number. |
|
| 206 | 190 | fn testSingleNum(pool: *mut Pool) -> i32 { |
|
| 207 | 191 | reset(pool); |
|
| 208 | 192 | let root = num(pool, 42); |
|
| 209 | - | if try! eval(&pool.nodes[..], root) != 42 { |
|
| 210 | - | return 1; |
|
| 211 | - | } |
|
| 212 | - | if countNodes(&pool.nodes[..], root) != 1 { |
|
| 213 | - | return 2; |
|
| 214 | - | } |
|
| 193 | + | assert try! eval(&pool.nodes[..], root) == 42; |
|
| 194 | + | assert countNodes(&pool.nodes[..], root) == 1; |
|
| 215 | 195 | return 0; |
|
| 216 | 196 | } |
|
| 217 | 197 | ||
| 218 | 198 | @default fn main() -> i32 { |
|
| 219 | 199 | let mut pool: Pool = Pool { nodes: [Expr::Num(0); 64], count: 0 }; |
lib/std/arch/rv64/tests/prog.hanoi.rad
+16 -48
| 39 | 39 | } |
|
| 40 | 40 | ||
| 41 | 41 | /// Verify total move count. |
|
| 42 | 42 | fn testMoveCount(ml: *MoveLog) -> i32 { |
|
| 43 | 43 | // For N disks, there are 2^N - 1 moves. |
|
| 44 | - | if ml.count != MAX_MOVES { |
|
| 45 | - | return 1; |
|
| 46 | - | } |
|
| 44 | + | assert ml.count == MAX_MOVES; |
|
| 47 | 45 | return 0; |
|
| 48 | 46 | } |
|
| 49 | 47 | ||
| 50 | 48 | /// Verify specific moves. |
|
| 51 | 49 | fn testSpecificMoves(ml: *MoveLog) -> i32 { |
|
| 52 | 50 | // First move: smallest disk (1) from peg 0 to peg 2. |
|
| 53 | - | if ml.moves[0].disk != 1 { |
|
| 54 | - | return 1; |
|
| 55 | - | } |
|
| 56 | - | if ml.moves[0].from != 0 { |
|
| 57 | - | return 2; |
|
| 58 | - | } |
|
| 59 | - | if ml.moves[0].to != 2 { |
|
| 60 | - | return 3; |
|
| 61 | - | } |
|
| 51 | + | assert ml.moves[0].disk == 1; |
|
| 52 | + | assert ml.moves[0].from == 0; |
|
| 53 | + | assert ml.moves[0].to == 2; |
|
| 62 | 54 | ||
| 63 | 55 | // Middle move (index 31): disk 6 from peg 0 to peg 1. |
|
| 64 | - | if ml.moves[31].disk != 6 { |
|
| 65 | - | return 4; |
|
| 66 | - | } |
|
| 67 | - | if ml.moves[31].from != 0 { |
|
| 68 | - | return 5; |
|
| 69 | - | } |
|
| 70 | - | if ml.moves[31].to != 1 { |
|
| 71 | - | return 6; |
|
| 72 | - | } |
|
| 56 | + | assert ml.moves[31].disk == 6; |
|
| 57 | + | assert ml.moves[31].from == 0; |
|
| 58 | + | assert ml.moves[31].to == 1; |
|
| 73 | 59 | ||
| 74 | 60 | // Last move: smallest disk (1) from peg 2 to peg 1. |
|
| 75 | - | if ml.moves[62].disk != 1 { |
|
| 76 | - | return 7; |
|
| 77 | - | } |
|
| 78 | - | if ml.moves[62].from != 2 { |
|
| 79 | - | return 8; |
|
| 80 | - | } |
|
| 81 | - | if ml.moves[62].to != 1 { |
|
| 82 | - | return 9; |
|
| 83 | - | } |
|
| 61 | + | assert ml.moves[62].disk == 1; |
|
| 62 | + | assert ml.moves[62].from == 2; |
|
| 63 | + | assert ml.moves[62].to == 1; |
|
| 84 | 64 | return 0; |
|
| 85 | 65 | } |
|
| 86 | 66 | ||
| 87 | 67 | /// Peg state: array of 3 pegs, each holding up to NUM_DISKS disks. |
|
| 88 | 68 | /// top[p] = number of disks currently on peg p. |
| 125 | 105 | }; |
|
| 126 | 106 | ||
| 127 | 107 | // Initialize: all disks on peg 0, largest at bottom. |
|
| 128 | 108 | let mut d: u32 = NUM_DISKS; |
|
| 129 | 109 | while d >= 1 { |
|
| 130 | - | if not pegPush(&mut pegs, 0, d) { |
|
| 131 | - | return 1; |
|
| 132 | - | } |
|
| 110 | + | assert pegPush(&mut pegs, 0, d); |
|
| 133 | 111 | if d == 0 { |
|
| 134 | 112 | break; |
|
| 135 | 113 | } |
|
| 136 | 114 | d -= 1; |
|
| 137 | 115 | } |
| 139 | 117 | // Replay all moves. |
|
| 140 | 118 | let mut i: u32 = 0; |
|
| 141 | 119 | while i < ml.count { |
|
| 142 | 120 | let m = ml.moves[i]; |
|
| 143 | 121 | let disk = pegPop(&mut pegs, m.from); |
|
| 144 | - | if disk != m.disk { |
|
| 145 | - | return 2; |
|
| 146 | - | } |
|
| 147 | - | if not pegPush(&mut pegs, m.to, disk) { |
|
| 148 | - | return 3; |
|
| 149 | - | } |
|
| 122 | + | assert disk == m.disk; |
|
| 123 | + | assert pegPush(&mut pegs, m.to, disk); |
|
| 150 | 124 | i += 1; |
|
| 151 | 125 | } |
|
| 152 | 126 | ||
| 153 | 127 | // All disks should be on peg 1. |
|
| 154 | - | if pegs.top[0] != 0 { |
|
| 155 | - | return 4; |
|
| 156 | - | } |
|
| 157 | - | if pegs.top[1] != NUM_DISKS { |
|
| 158 | - | return 5; |
|
| 159 | - | } |
|
| 160 | - | if pegs.top[2] != 0 { |
|
| 161 | - | return 6; |
|
| 162 | - | } |
|
| 128 | + | assert pegs.top[0] == 0; |
|
| 129 | + | assert pegs.top[1] == NUM_DISKS; |
|
| 130 | + | assert pegs.top[2] == 0; |
|
| 163 | 131 | return 0; |
|
| 164 | 132 | } |
|
| 165 | 133 | ||
| 166 | 134 | @default fn main() -> i32 { |
|
| 167 | 135 | let mut ml = MoveLog { |
lib/std/arch/rv64/tests/prog.huffman.rad
+12 -36
| 233 | 233 | ||
| 234 | 234 | fn testBasic(s: *mut HuffState) -> i32 { |
|
| 235 | 235 | let freqs: [u32; 5] = [5, 9, 12, 13, 16]; |
|
| 236 | 236 | let root: u32 = buildTree(s, &freqs[..]); |
|
| 237 | 237 | ||
| 238 | - | if s.nodes[root].freq != 55 { |
|
| 239 | - | return 1; |
|
| 240 | - | } |
|
| 238 | + | assert s.nodes[root].freq == 55; |
|
| 241 | 239 | ||
| 242 | 240 | resetCodes(s); |
|
| 243 | 241 | generateCodes(s, root, 0, 0); |
|
| 244 | 242 | ||
| 245 | 243 | // All symbols should have non-zero code lengths. |
|
| 246 | 244 | let mut i: u32 = 0; |
|
| 247 | 245 | while i < 5 { |
|
| 248 | - | if s.codeLen[i] == 0 { |
|
| 249 | - | return 2; |
|
| 250 | - | } |
|
| 246 | + | assert s.codeLen[i] != 0; |
|
| 251 | 247 | i += 1; |
|
| 252 | 248 | } |
|
| 253 | 249 | ||
| 254 | 250 | // No two symbols at the same depth should have the same code. |
|
| 255 | 251 | let mut a: u32 = 0; |
|
| 256 | 252 | while a < 5 { |
|
| 257 | 253 | let mut b: u32 = a + 1; |
|
| 258 | 254 | while b < 5 { |
|
| 259 | 255 | if s.codeLen[a] == s.codeLen[b] { |
|
| 260 | - | if s.codeBits[a] == s.codeBits[b] { |
|
| 261 | - | return 3; |
|
| 262 | - | } |
|
| 256 | + | assert s.codeBits[a] != s.codeBits[b]; |
|
| 263 | 257 | } |
|
| 264 | 258 | b += 1; |
|
| 265 | 259 | } |
|
| 266 | 260 | a += 1; |
|
| 267 | 261 | } |
| 280 | 274 | encode(s, &msg[..]); |
|
| 281 | 275 | ||
| 282 | 276 | let mut decoded: [u32; 16] = [0; 16]; |
|
| 283 | 277 | let count: u32 = decode(s, root, 16, &mut decoded[..]); |
|
| 284 | 278 | ||
| 285 | - | if count != 16 { |
|
| 286 | - | return 1; |
|
| 287 | - | } |
|
| 279 | + | assert count == 16; |
|
| 288 | 280 | ||
| 289 | 281 | // Verify round-trip. |
|
| 290 | 282 | for expected, i in msg { |
|
| 291 | 283 | if decoded[i] != expected { |
|
| 292 | 284 | return i as i32 + 2; |
| 312 | 304 | shortestLen = s.codeLen[i]; |
|
| 313 | 305 | shortestSym = i; |
|
| 314 | 306 | } |
|
| 315 | 307 | i += 1; |
|
| 316 | 308 | } |
|
| 317 | - | if shortestSym != 0 { |
|
| 318 | - | return 1; |
|
| 319 | - | } |
|
| 309 | + | assert shortestSym == 0; |
|
| 320 | 310 | ||
| 321 | 311 | let msg: [u32; 12] = [0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2]; |
|
| 322 | 312 | encode(s, &msg[..]); |
|
| 323 | 313 | ||
| 324 | 314 | let mut decoded: [u32; 12] = [0; 12]; |
|
| 325 | 315 | let count: u32 = decode(s, root, 12, &mut decoded[..]); |
|
| 326 | - | if count != 12 { |
|
| 327 | - | return 2; |
|
| 328 | - | } |
|
| 316 | + | assert count == 12; |
|
| 329 | 317 | ||
| 330 | 318 | for expected, i in msg { |
|
| 331 | - | if decoded[i] != expected { |
|
| 332 | - | return 3; |
|
| 333 | - | } |
|
| 319 | + | assert decoded[i] == expected; |
|
| 334 | 320 | } |
|
| 335 | 321 | ||
| 336 | 322 | return 0; |
|
| 337 | 323 | } |
|
| 338 | 324 | ||
| 339 | 325 | fn testUniform(s: *mut HuffState) -> i32 { |
|
| 340 | 326 | let freqs: [u32; 8] = [10, 10, 10, 10, 10, 10, 10, 10]; |
|
| 341 | 327 | let root: u32 = buildTree(s, &freqs[..]); |
|
| 342 | 328 | ||
| 343 | - | if s.nodes[root].freq != 80 { |
|
| 344 | - | return 1; |
|
| 345 | - | } |
|
| 329 | + | assert s.nodes[root].freq == 80; |
|
| 346 | 330 | ||
| 347 | 331 | resetCodes(s); |
|
| 348 | 332 | generateCodes(s, root, 0, 0); |
|
| 349 | 333 | ||
| 350 | 334 | // All 8 symbols should have code length 3 (8 = 2^3). |
|
| 351 | 335 | let mut i: u32 = 0; |
|
| 352 | 336 | while i < 8 { |
|
| 353 | - | if s.codeLen[i] != 3 { |
|
| 354 | - | return 2; |
|
| 355 | - | } |
|
| 337 | + | assert s.codeLen[i] == 3; |
|
| 356 | 338 | i += 1; |
|
| 357 | 339 | } |
|
| 358 | 340 | ||
| 359 | 341 | let msg: [u32; 8] = [0, 1, 2, 3, 4, 5, 6, 7]; |
|
| 360 | 342 | encode(s, &msg[..]); |
|
| 361 | 343 | ||
| 362 | - | if s.bitCount != 24 { |
|
| 363 | - | return 3; |
|
| 364 | - | } |
|
| 344 | + | assert s.bitCount == 24; |
|
| 365 | 345 | ||
| 366 | 346 | let mut decoded: [u32; 8] = [0; 8]; |
|
| 367 | 347 | let count: u32 = decode(s, root, 8, &mut decoded[..]); |
|
| 368 | - | if count != 8 { |
|
| 369 | - | return 4; |
|
| 370 | - | } |
|
| 348 | + | assert count == 8; |
|
| 371 | 349 | for expected, i in msg { |
|
| 372 | - | if decoded[i] != expected { |
|
| 373 | - | return 5; |
|
| 374 | - | } |
|
| 350 | + | assert decoded[i] == expected; |
|
| 375 | 351 | } |
|
| 376 | 352 | ||
| 377 | 353 | return 0; |
|
| 378 | 354 | } |
|
| 379 | 355 |
lib/std/arch/rv64/tests/prog.hybridsort.rad
+4 -12
| 103 | 103 | // Sort with insertion sort. |
|
| 104 | 104 | let mut a: [i32; 24] = [0; 24]; |
|
| 105 | 105 | copy(&mut a[..], &orig[..]); |
|
| 106 | 106 | insertionSort(&mut a[..]); |
|
| 107 | 107 | ||
| 108 | - | if not isSorted(&a[..]) { |
|
| 109 | - | return 1; |
|
| 110 | - | } |
|
| 111 | - | if sum(&a[..]) != origSum { |
|
| 112 | - | return 2; |
|
| 113 | - | } |
|
| 108 | + | assert isSorted(&a[..]); |
|
| 109 | + | assert sum(&a[..]) == origSum; |
|
| 114 | 110 | ||
| 115 | 111 | // Sort with selection sort. |
|
| 116 | 112 | let mut b: [i32; 24] = [0; 24]; |
|
| 117 | 113 | copy(&mut b[..], &orig[..]); |
|
| 118 | 114 | selectionSort(&mut b[..]); |
|
| 119 | 115 | ||
| 120 | - | if not isSorted(&b[..]) { |
|
| 121 | - | return 3; |
|
| 122 | - | } |
|
| 123 | - | if sum(&b[..]) != origSum { |
|
| 124 | - | return 4; |
|
| 125 | - | } |
|
| 116 | + | assert isSorted(&b[..]); |
|
| 117 | + | assert sum(&b[..]) == origSum; |
|
| 126 | 118 | ||
| 127 | 119 | // Both algorithms must produce the same result. |
|
| 128 | 120 | let r = arraysEqual(&a[..], &b[..]); |
|
| 129 | 121 | if r != 0 { |
|
| 130 | 122 | return 10 + r; |
lib/std/arch/rv64/tests/prog.linkedlist.rad
+25 -75
| 112 | 112 | fn testPushLength(list: *mut List) -> i32 { |
|
| 113 | 113 | push(list, 10); |
|
| 114 | 114 | push(list, 20); |
|
| 115 | 115 | push(list, 30); |
|
| 116 | 116 | ||
| 117 | - | if length(list) != 3 { |
|
| 118 | - | return 1; |
|
| 119 | - | } |
|
| 117 | + | assert length(list) == 3; |
|
| 120 | 118 | // Head should be most recently pushed. |
|
| 121 | 119 | let v0 = valueAt(list, 0) else { |
|
| 122 | 120 | return 2; |
|
| 123 | 121 | }; |
|
| 124 | - | if v0 != 30 { |
|
| 125 | - | return 2; |
|
| 126 | - | } |
|
| 122 | + | assert v0 == 30; |
|
| 127 | 123 | let v1 = valueAt(list, 1) else { |
|
| 128 | 124 | return 3; |
|
| 129 | 125 | }; |
|
| 130 | - | if v1 != 20 { |
|
| 131 | - | return 3; |
|
| 132 | - | } |
|
| 126 | + | assert v1 == 20; |
|
| 133 | 127 | let v2 = valueAt(list, 2) else { |
|
| 134 | 128 | return 4; |
|
| 135 | 129 | }; |
|
| 136 | - | if v2 != 10 { |
|
| 137 | - | return 4; |
|
| 138 | - | } |
|
| 130 | + | assert v2 == 10; |
|
| 139 | 131 | return 0; |
|
| 140 | 132 | } |
|
| 141 | 133 | ||
| 142 | 134 | /// Test pop. |
|
| 143 | 135 | fn testPop(list: *mut List) -> i32 { |
|
| 144 | 136 | let v = pop(list) else { |
|
| 145 | 137 | return 1; |
|
| 146 | 138 | }; |
|
| 147 | - | if v != 30 { |
|
| 148 | - | return 1; |
|
| 149 | - | } |
|
| 150 | - | if length(list) != 2 { |
|
| 151 | - | return 2; |
|
| 152 | - | } |
|
| 139 | + | assert v == 30; |
|
| 140 | + | assert length(list) == 2; |
|
| 153 | 141 | let v0 = valueAt(list, 0) else { |
|
| 154 | 142 | return 3; |
|
| 155 | 143 | }; |
|
| 156 | - | if v0 != 20 { |
|
| 157 | - | return 3; |
|
| 158 | - | } |
|
| 144 | + | assert v0 == 20; |
|
| 159 | 145 | return 0; |
|
| 160 | 146 | } |
|
| 161 | 147 | ||
| 162 | 148 | /// Test find. |
|
| 163 | 149 | fn testFind(list: *mut List) -> i32 { |
|
| 164 | 150 | // 20 should be found. |
|
| 165 | - | if find(list, 20) == nil { |
|
| 166 | - | return 1; |
|
| 167 | - | } |
|
| 151 | + | assert find(list, 20) != nil; |
|
| 168 | 152 | // 10 should be found. |
|
| 169 | - | if find(list, 10) == nil { |
|
| 170 | - | return 2; |
|
| 171 | - | } |
|
| 153 | + | assert find(list, 10) != nil; |
|
| 172 | 154 | // 30 was popped, should not be found. |
|
| 173 | - | if find(list, 30) != nil { |
|
| 174 | - | return 3; |
|
| 175 | - | } |
|
| 155 | + | assert find(list, 30) == nil; |
|
| 176 | 156 | // 99 never inserted. |
|
| 177 | - | if find(list, 99) != nil { |
|
| 178 | - | return 4; |
|
| 179 | - | } |
|
| 157 | + | assert find(list, 99) == nil; |
|
| 180 | 158 | return 0; |
|
| 181 | 159 | } |
|
| 182 | 160 | ||
| 183 | 161 | /// Test reverse. |
|
| 184 | 162 | fn testReverse(list: *mut List) -> i32 { |
| 191 | 169 | let sumBefore = sum(list); |
|
| 192 | 170 | ||
| 193 | 171 | reverse(list); |
|
| 194 | 172 | // List should be: 10 -> 20 -> 40 -> 50 |
|
| 195 | 173 | ||
| 196 | - | if length(list) != 4 { |
|
| 197 | - | return 1; |
|
| 198 | - | } |
|
| 174 | + | assert length(list) == 4; |
|
| 199 | 175 | ||
| 200 | 176 | let v0 = valueAt(list, 0) else { |
|
| 201 | 177 | return 2; |
|
| 202 | 178 | }; |
|
| 203 | - | if v0 != 10 { |
|
| 204 | - | return 2; |
|
| 205 | - | } |
|
| 179 | + | assert v0 == 10; |
|
| 206 | 180 | let v1 = valueAt(list, 1) else { |
|
| 207 | 181 | return 3; |
|
| 208 | 182 | }; |
|
| 209 | - | if v1 != 20 { |
|
| 210 | - | return 3; |
|
| 211 | - | } |
|
| 183 | + | assert v1 == 20; |
|
| 212 | 184 | let v2 = valueAt(list, 2) else { |
|
| 213 | 185 | return 4; |
|
| 214 | 186 | }; |
|
| 215 | - | if v2 != 40 { |
|
| 216 | - | return 4; |
|
| 217 | - | } |
|
| 187 | + | assert v2 == 40; |
|
| 218 | 188 | let v3 = valueAt(list, 3) else { |
|
| 219 | 189 | return 5; |
|
| 220 | 190 | }; |
|
| 221 | - | if v3 != 50 { |
|
| 222 | - | return 5; |
|
| 223 | - | } |
|
| 191 | + | assert v3 == 50; |
|
| 224 | 192 | ||
| 225 | - | if sum(list) != sumBefore { |
|
| 226 | - | return 6; |
|
| 227 | - | } |
|
| 193 | + | assert sum(list) == sumBefore; |
|
| 228 | 194 | return 0; |
|
| 229 | 195 | } |
|
| 230 | 196 | ||
| 231 | 197 | /// Test building a larger list. |
|
| 232 | 198 | fn testLargerList(list: *mut List) -> i32 { |
| 237 | 203 | while i < 32 { |
|
| 238 | 204 | push(list, i as i32 * 3); |
|
| 239 | 205 | i += 1; |
|
| 240 | 206 | } |
|
| 241 | 207 | ||
| 242 | - | if length(list) != 32 { |
|
| 243 | - | return 1; |
|
| 244 | - | } |
|
| 208 | + | assert length(list) == 32; |
|
| 245 | 209 | ||
| 246 | 210 | // Sum should be 3 * (0 + 1 + ... + 31) = 3 * 496 = 1488 |
|
| 247 | - | if sum(list) != 1488 { |
|
| 248 | - | return 2; |
|
| 249 | - | } |
|
| 211 | + | assert sum(list) == 1488; |
|
| 250 | 212 | ||
| 251 | 213 | // Reverse and verify sum is preserved. |
|
| 252 | 214 | reverse(list); |
|
| 253 | - | if sum(list) != 1488 { |
|
| 254 | - | return 3; |
|
| 255 | - | } |
|
| 215 | + | assert sum(list) == 1488; |
|
| 256 | 216 | ||
| 257 | 217 | // After reverse, head should be 0 (first pushed), tail should be 93 (last pushed). |
|
| 258 | 218 | let head = valueAt(list, 0) else { |
|
| 259 | 219 | return 4; |
|
| 260 | 220 | }; |
|
| 261 | - | if head != 0 { |
|
| 262 | - | return 4; |
|
| 263 | - | } |
|
| 221 | + | assert head == 0; |
|
| 264 | 222 | let tail = valueAt(list, 31) else { |
|
| 265 | 223 | return 5; |
|
| 266 | 224 | }; |
|
| 267 | - | if tail != 93 { |
|
| 268 | - | return 5; |
|
| 269 | - | } |
|
| 225 | + | assert tail == 93; |
|
| 270 | 226 | ||
| 271 | 227 | // Pop all and verify decreasing original order. |
|
| 272 | 228 | let mut j: u32 = 0; |
|
| 273 | 229 | while j < 32 { |
|
| 274 | 230 | let v = pop(list) else { |
|
| 275 | 231 | return 6; |
|
| 276 | 232 | }; |
|
| 277 | 233 | let expected = j as i32 * 3; |
|
| 278 | - | if v != expected { |
|
| 279 | - | return 6; |
|
| 280 | - | } |
|
| 234 | + | assert v == expected; |
|
| 281 | 235 | j += 1; |
|
| 282 | 236 | } |
|
| 283 | 237 | ||
| 284 | - | if length(list) != 0 { |
|
| 285 | - | return 7; |
|
| 286 | - | } |
|
| 238 | + | assert length(list) == 0; |
|
| 287 | 239 | ||
| 288 | 240 | // Pop from empty list should return nil. |
|
| 289 | - | if pop(list) != nil { |
|
| 290 | - | return 8; |
|
| 291 | - | } |
|
| 241 | + | assert pop(list) == nil; |
|
| 292 | 242 | return 0; |
|
| 293 | 243 | } |
|
| 294 | 244 | ||
| 295 | 245 | @default fn main() -> i32 { |
|
| 296 | 246 | let mut list: List = List { |
lib/std/arch/rv64/tests/prog.lzw.rad
+16 -16
| 185 | 185 | ||
| 186 | 186 | fn testSimple(s: *mut LzwState) -> i32 { |
|
| 187 | 187 | let data: *[u8] = "ABABABABAB"; |
|
| 188 | 188 | encode(s, data); |
|
| 189 | 189 | ||
| 190 | - | if s.encoded[s.encLen - 1] != EOI_CODE { return 1; } |
|
| 190 | + | assert s.encoded[s.encLen - 1] == EOI_CODE; |
|
| 191 | 191 | ||
| 192 | 192 | decode(s); |
|
| 193 | - | if s.decLen != 10 { return 2; } |
|
| 193 | + | assert s.decLen == 10; |
|
| 194 | 194 | let mut i: u32 = 0; |
|
| 195 | 195 | while i < 10 { |
|
| 196 | - | if s.decoded[i] != data[i] { return 3; } |
|
| 196 | + | assert s.decoded[i] == data[i]; |
|
| 197 | 197 | i += 1; |
|
| 198 | 198 | } |
|
| 199 | 199 | return 0; |
|
| 200 | 200 | } |
|
| 201 | 201 | ||
| 202 | 202 | fn testDistinct(s: *mut LzwState) -> i32 { |
|
| 203 | 203 | let data: [u8; 16] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; |
|
| 204 | 204 | encode(s, &data[..]); |
|
| 205 | 205 | ||
| 206 | 206 | decode(s); |
|
| 207 | - | if s.decLen != 16 { return 1; } |
|
| 207 | + | assert s.decLen == 16; |
|
| 208 | 208 | let mut i: u32 = 0; |
|
| 209 | 209 | while i < 16 { |
|
| 210 | - | if s.decoded[i] != data[i] { return 2; } |
|
| 210 | + | assert s.decoded[i] == data[i]; |
|
| 211 | 211 | i += 1; |
|
| 212 | 212 | } |
|
| 213 | 213 | return 0; |
|
| 214 | 214 | } |
|
| 215 | 215 | ||
| 216 | 216 | fn testRepetitive(s: *mut LzwState) -> i32 { |
|
| 217 | 217 | let mut data: [u8; 64] = [65; 64]; |
|
| 218 | 218 | encode(s, &data[..]); |
|
| 219 | 219 | ||
| 220 | - | if s.encLen >= 32 { return 1; } |
|
| 220 | + | assert s.encLen < 32; |
|
| 221 | 221 | ||
| 222 | 222 | decode(s); |
|
| 223 | - | if s.decLen != 64 { return 2; } |
|
| 223 | + | assert s.decLen == 64; |
|
| 224 | 224 | let mut i: u32 = 0; |
|
| 225 | 225 | while i < 64 { |
|
| 226 | - | if s.decoded[i] != 65 { return 3; } |
|
| 226 | + | assert s.decoded[i] == 65; |
|
| 227 | 227 | i += 1; |
|
| 228 | 228 | } |
|
| 229 | 229 | return 0; |
|
| 230 | 230 | } |
|
| 231 | 231 | ||
| 232 | 232 | fn testMixed(s: *mut LzwState) -> i32 { |
|
| 233 | 233 | let data: *[u8] = "TOBEORNOTTOBEORTOBEORNOT"; |
|
| 234 | 234 | encode(s, data); |
|
| 235 | 235 | ||
| 236 | 236 | decode(s); |
|
| 237 | - | if s.decLen != 24 { return 1; } |
|
| 237 | + | assert s.decLen == 24; |
|
| 238 | 238 | let mut i: u32 = 0; |
|
| 239 | 239 | while i < 24 { |
|
| 240 | - | if s.decoded[i] != data[i] { return 2; } |
|
| 240 | + | assert s.decoded[i] == data[i]; |
|
| 241 | 241 | i += 1; |
|
| 242 | 242 | } |
|
| 243 | 243 | ||
| 244 | - | if s.encLen - 1 >= 24 { return 3; } |
|
| 244 | + | assert s.encLen - 1 < 24; |
|
| 245 | 245 | ||
| 246 | 246 | return 0; |
|
| 247 | 247 | } |
|
| 248 | 248 | ||
| 249 | 249 | fn testEmpty(s: *mut LzwState) -> i32 { |
|
| 250 | 250 | encode(s, &[]); |
|
| 251 | - | if s.encLen != 1 { return 1; } |
|
| 252 | - | if s.encoded[0] != EOI_CODE { return 2; } |
|
| 251 | + | assert s.encLen == 1; |
|
| 252 | + | assert s.encoded[0] == EOI_CODE; |
|
| 253 | 253 | ||
| 254 | 254 | decode(s); |
|
| 255 | - | if s.decLen != 0 { return 3; } |
|
| 255 | + | assert s.decLen == 0; |
|
| 256 | 256 | return 0; |
|
| 257 | 257 | } |
|
| 258 | 258 | ||
| 259 | 259 | fn testSingle(s: *mut LzwState) -> i32 { |
|
| 260 | 260 | let data: *[u8] = "*"; |
|
| 261 | 261 | encode(s, data); |
|
| 262 | 262 | ||
| 263 | 263 | decode(s); |
|
| 264 | - | if s.decLen != 1 { return 1; } |
|
| 265 | - | if s.decoded[0] != 42 { return 2; } |
|
| 264 | + | assert s.decLen == 1; |
|
| 265 | + | assert s.decoded[0] == 42; |
|
| 266 | 266 | return 0; |
|
| 267 | 267 | } |
|
| 268 | 268 | ||
| 269 | 269 | @default fn main() -> i32 { |
|
| 270 | 270 | let mut encDict: [DictEntry; 512] = [DictEntry { prefix: 0xFFFF, suffix: 0 }; 512]; |
lib/std/arch/rv64/tests/prog.matmul.rad
+2 -6
| 69 | 69 | } |
|
| 70 | 70 | ||
| 71 | 71 | /// Multiply matrices multiple times to test repeated computation. |
|
| 72 | 72 | fn testRepeatedMultiply(c: *mut Mat4, a: *Mat4, b: *Mat4) -> i32 { |
|
| 73 | 73 | // First pass already done, trace = 13+43+43+85 = 184. |
|
| 74 | - | if trace(c) != 184 { |
|
| 75 | - | return 1; |
|
| 76 | - | } |
|
| 74 | + | assert trace(c) == 184; |
|
| 77 | 75 | ||
| 78 | 76 | // Zero out c and re-multiply to ensure idempotent. |
|
| 79 | 77 | zero(c); |
|
| 80 | 78 | matmul(c, a, b); |
|
| 81 | - | if trace(c) != 184 { |
|
| 82 | - | return 2; |
|
| 83 | - | } |
|
| 79 | + | assert trace(c) == 184; |
|
| 84 | 80 | return 0; |
|
| 85 | 81 | } |
|
| 86 | 82 | ||
| 87 | 83 | @default fn main() -> i32 { |
|
| 88 | 84 | let a = Mat4 { rows: [ |
lib/std/arch/rv64/tests/prog.mersenne.rad
+16 -16
| 86 | 86 | ||
| 87 | 87 | fn testKnownSequence(s: *mut MtState) -> i32 { |
|
| 88 | 88 | mtInit(s, 1); |
|
| 89 | 89 | ||
| 90 | 90 | let v0: u32 = mtNext(s); |
|
| 91 | - | if v0 != 1791095845 { return 1; } |
|
| 91 | + | assert v0 == 1791095845; |
|
| 92 | 92 | ||
| 93 | 93 | let v1: u32 = mtNext(s); |
|
| 94 | - | if v1 != 4282876139 { return 2; } |
|
| 94 | + | assert v1 == 4282876139; |
|
| 95 | 95 | ||
| 96 | 96 | let v2: u32 = mtNext(s); |
|
| 97 | - | if v2 != 3093770124 { return 3; } |
|
| 97 | + | assert v2 == 3093770124; |
|
| 98 | 98 | ||
| 99 | 99 | let v3: u32 = mtNext(s); |
|
| 100 | - | if v3 != 4005303368 { return 4; } |
|
| 100 | + | assert v3 == 4005303368; |
|
| 101 | 101 | ||
| 102 | 102 | let v4: u32 = mtNext(s); |
|
| 103 | - | if v4 != 491263 { return 5; } |
|
| 103 | + | assert v4 == 491263; |
|
| 104 | 104 | ||
| 105 | 105 | return 0; |
|
| 106 | 106 | } |
|
| 107 | 107 | ||
| 108 | 108 | fn testDeterminism(s: *mut MtState) -> i32 { |
| 135 | 135 | let b: u32 = mtNext(s); |
|
| 136 | 136 | ||
| 137 | 137 | mtInit(s, 3); |
|
| 138 | 138 | let c: u32 = mtNext(s); |
|
| 139 | 139 | ||
| 140 | - | if a == b { return 1; } |
|
| 141 | - | if b == c { return 2; } |
|
| 142 | - | if a == c { return 3; } |
|
| 140 | + | assert a != b; |
|
| 141 | + | assert b != c; |
|
| 142 | + | assert a != c; |
|
| 143 | 143 | ||
| 144 | 144 | return 0; |
|
| 145 | 145 | } |
|
| 146 | 146 | ||
| 147 | 147 | fn testChiSquared(s: *mut MtState) -> i32 { |
| 169 | 169 | let diff: i32 = obs - exp; |
|
| 170 | 170 | chi2Scaled += (diff * diff) as u32; |
|
| 171 | 171 | b += 1; |
|
| 172 | 172 | } |
|
| 173 | 173 | ||
| 174 | - | if chi2Scaled > 5000 { return 1; } |
|
| 174 | + | assert chi2Scaled <= 5000; |
|
| 175 | 175 | ||
| 176 | 176 | b = 0; |
|
| 177 | 177 | while b < NUM_BINS { |
|
| 178 | - | if bins[b] == 0 { return 2; } |
|
| 178 | + | assert bins[b] != 0; |
|
| 179 | 179 | b += 1; |
|
| 180 | 180 | } |
|
| 181 | 181 | ||
| 182 | 182 | b = 0; |
|
| 183 | 183 | while b < NUM_BINS { |
|
| 184 | - | if bins[b] > NUM_SAMPLES / 2 { return 3; } |
|
| 184 | + | assert bins[b] <= NUM_SAMPLES / 2; |
|
| 185 | 185 | b += 1; |
|
| 186 | 186 | } |
|
| 187 | 187 | ||
| 188 | 188 | return 0; |
|
| 189 | 189 | } |
| 204 | 204 | while i < 700 { |
|
| 205 | 205 | last2 = mtNext(s); |
|
| 206 | 206 | i += 1; |
|
| 207 | 207 | } |
|
| 208 | 208 | ||
| 209 | - | if last != last2 { return 1; } |
|
| 209 | + | assert last == last2; |
|
| 210 | 210 | ||
| 211 | 211 | let mut more: u32 = 0; |
|
| 212 | 212 | i = 0; |
|
| 213 | 213 | while i < 700 { |
|
| 214 | 214 | more = mtNext(s); |
|
| 215 | 215 | i += 1; |
|
| 216 | 216 | } |
|
| 217 | - | if more == 0 { return 2; } |
|
| 217 | + | assert more != 0; |
|
| 218 | 218 | ||
| 219 | 219 | return 0; |
|
| 220 | 220 | } |
|
| 221 | 221 | ||
| 222 | 222 | fn testBitCoverage(s: *mut MtState) -> i32 { |
| 231 | 231 | orAll |= v; |
|
| 232 | 232 | andAll &= v; |
|
| 233 | 233 | i += 1; |
|
| 234 | 234 | } |
|
| 235 | 235 | ||
| 236 | - | if orAll != 0xFFFFFFFF { return 1; } |
|
| 237 | - | if andAll == 0xFFFFFFFF { return 2; } |
|
| 238 | - | if andAll != 0 { return 3; } |
|
| 236 | + | assert orAll == 0xFFFFFFFF; |
|
| 237 | + | assert andAll != 0xFFFFFFFF; |
|
| 238 | + | assert andAll == 0; |
|
| 239 | 239 | ||
| 240 | 240 | return 0; |
|
| 241 | 241 | } |
|
| 242 | 242 | ||
| 243 | 243 | @default fn main() -> i32 { |
lib/std/arch/rv64/tests/prog.nqueens.rad
+10 -14
| 77 | 77 | ||
| 78 | 78 | let mut i: u32 = 0; |
|
| 79 | 79 | while i < 8 { |
|
| 80 | 80 | let mut j: u32 = i + 1; |
|
| 81 | 81 | while j < 8 { |
|
| 82 | - | if solution[i] == solution[j] { |
|
| 83 | - | return 1; |
|
| 84 | - | } |
|
| 82 | + | assert solution[i] != solution[j]; |
|
| 85 | 83 | let rowDiff: i32 = j as i32 - i as i32; |
|
| 86 | 84 | let colDiff: i32 = solution[j] - solution[i]; |
|
| 87 | - | if colDiff == rowDiff or colDiff == 0 - rowDiff { |
|
| 88 | - | return 2; |
|
| 89 | - | } |
|
| 85 | + | assert colDiff != rowDiff and colDiff != 0 - rowDiff; |
|
| 90 | 86 | j += 1; |
|
| 91 | 87 | } |
|
| 92 | 88 | i += 1; |
|
| 93 | 89 | } |
|
| 94 | 90 |
| 109 | 105 | fn testDeterminism(b: *mut Board) -> i32 { |
|
| 110 | 106 | let count1: u32 = solveNQueens(b, 8); |
|
| 111 | 107 | let count2: u32 = solveNQueens(b, 8); |
|
| 112 | 108 | let count3: u32 = solveNQueens(b, 8); |
|
| 113 | 109 | ||
| 114 | - | if count1 != 92 { return 1; } |
|
| 115 | - | if count2 != 92 { return 2; } |
|
| 116 | - | if count3 != 92 { return 3; } |
|
| 110 | + | assert count1 == 92; |
|
| 111 | + | assert count2 == 92; |
|
| 112 | + | assert count3 == 92; |
|
| 117 | 113 | return 0; |
|
| 118 | 114 | } |
|
| 119 | 115 | ||
| 120 | 116 | fn testProperties() -> i32 { |
|
| 121 | 117 | let expected: [u32; 9] = [0, 1, 0, 0, 2, 10, 4, 40, 92]; |
|
| 122 | 118 | ||
| 123 | 119 | let mut n: u32 = 4; |
|
| 124 | 120 | while n <= 8 { |
|
| 125 | - | if expected[n] == 0 { return 1; } |
|
| 121 | + | assert expected[n] != 0; |
|
| 126 | 122 | n += 1; |
|
| 127 | 123 | } |
|
| 128 | 124 | ||
| 129 | - | if expected[2] != 0 { return 2; } |
|
| 130 | - | if expected[3] != 0 { return 3; } |
|
| 131 | - | if expected[7] <= expected[6] { return 4; } |
|
| 132 | - | if expected[8] <= expected[7] { return 5; } |
|
| 125 | + | assert expected[2] == 0; |
|
| 126 | + | assert expected[3] == 0; |
|
| 127 | + | assert expected[7] > expected[6]; |
|
| 128 | + | assert expected[8] > expected[7]; |
|
| 133 | 129 | ||
| 134 | 130 | return 0; |
|
| 135 | 131 | } |
|
| 136 | 132 | ||
| 137 | 133 | @default fn main() -> i32 { |
lib/std/arch/rv64/tests/prog.rbtree.rad
+21 -21
| 219 | 219 | while i < 32 { |
|
| 220 | 220 | insert(t, i); |
|
| 221 | 221 | i += 1; |
|
| 222 | 222 | } |
|
| 223 | 223 | ||
| 224 | - | if countNodes(t, t.root) != 32 { return 1; } |
|
| 225 | - | if t.pool[t.root].color != BLACK { return 2; } |
|
| 224 | + | assert countNodes(t, t.root) == 32; |
|
| 225 | + | assert t.pool[t.root].color == BLACK; |
|
| 226 | 226 | ||
| 227 | 227 | let bh: i32 = blackHeight(t, t.root); |
|
| 228 | - | if bh == -1 { return 3; } |
|
| 228 | + | assert bh != -1; |
|
| 229 | 229 | ||
| 230 | - | if not noRedRed(t, t.root) { return 4; } |
|
| 230 | + | assert noRedRed(t, t.root); |
|
| 231 | 231 | ||
| 232 | 232 | t.inorderCount = 0; |
|
| 233 | 233 | inorderWalk(t, t.root); |
|
| 234 | - | if t.inorderCount != 32 { return 5; } |
|
| 234 | + | assert t.inorderCount == 32; |
|
| 235 | 235 | let mut j: u32 = 0; |
|
| 236 | 236 | while j < 32 { |
|
| 237 | - | if t.inorder[j] != j as i32 { return 6; } |
|
| 237 | + | assert t.inorder[j] == j as i32; |
|
| 238 | 238 | j += 1; |
|
| 239 | 239 | } |
|
| 240 | 240 | ||
| 241 | 241 | return 0; |
|
| 242 | 242 | } |
| 251 | 251 | break; |
|
| 252 | 252 | } |
|
| 253 | 253 | i -= 1; |
|
| 254 | 254 | } |
|
| 255 | 255 | ||
| 256 | - | if countNodes(t, t.root) != 32 { return 1; } |
|
| 257 | - | if blackHeight(t, t.root) == -1 { return 2; } |
|
| 258 | - | if not noRedRed(t, t.root) { return 3; } |
|
| 256 | + | assert countNodes(t, t.root) == 32; |
|
| 257 | + | assert blackHeight(t, t.root) != -1; |
|
| 258 | + | assert noRedRed(t, t.root); |
|
| 259 | 259 | ||
| 260 | 260 | t.inorderCount = 0; |
|
| 261 | 261 | inorderWalk(t, t.root); |
|
| 262 | 262 | let mut j: u32 = 0; |
|
| 263 | 263 | while j < 32 { |
|
| 264 | - | if t.inorder[j] != j as i32 { return 4; } |
|
| 264 | + | assert t.inorder[j] == j as i32; |
|
| 265 | 265 | j += 1; |
|
| 266 | 266 | } |
|
| 267 | 267 | ||
| 268 | 268 | return 0; |
|
| 269 | 269 | } |
| 283 | 283 | inserted[val] = true; |
|
| 284 | 284 | count += 1; |
|
| 285 | 285 | } |
|
| 286 | 286 | } |
|
| 287 | 287 | ||
| 288 | - | if countNodes(t, t.root) != 48 { return 1; } |
|
| 289 | - | if blackHeight(t, t.root) == -1 { return 2; } |
|
| 290 | - | if not noRedRed(t, t.root) { return 3; } |
|
| 288 | + | assert countNodes(t, t.root) == 48; |
|
| 289 | + | assert blackHeight(t, t.root) != -1; |
|
| 290 | + | assert noRedRed(t, t.root); |
|
| 291 | 291 | ||
| 292 | 292 | let mut i: i32 = 0; |
|
| 293 | 293 | while i < 48 { |
|
| 294 | - | if not search(t, i) { return 4; } |
|
| 294 | + | assert search(t, i); |
|
| 295 | 295 | i += 1; |
|
| 296 | 296 | } |
|
| 297 | 297 | ||
| 298 | - | if search(t, -1) { return 5; } |
|
| 299 | - | if search(t, 48) { return 6; } |
|
| 300 | - | if search(t, 100) { return 7; } |
|
| 298 | + | assert not search(t, -1); |
|
| 299 | + | assert not search(t, 48); |
|
| 300 | + | assert not search(t, 100); |
|
| 301 | 301 | ||
| 302 | 302 | t.inorderCount = 0; |
|
| 303 | 303 | inorderWalk(t, t.root); |
|
| 304 | - | if t.inorderCount != 48 { return 8; } |
|
| 304 | + | assert t.inorderCount == 48; |
|
| 305 | 305 | let mut j: u32 = 0; |
|
| 306 | 306 | while j < 48 { |
|
| 307 | - | if t.inorder[j] != j as i32 { return 9; } |
|
| 307 | + | assert t.inorder[j] == j as i32; |
|
| 308 | 308 | j += 1; |
|
| 309 | 309 | } |
|
| 310 | 310 | ||
| 311 | 311 | return 0; |
|
| 312 | 312 | } |
| 319 | 319 | insert(t, i); |
|
| 320 | 320 | i += 1; |
|
| 321 | 321 | } |
|
| 322 | 322 | ||
| 323 | 323 | let bh: i32 = blackHeight(t, t.root); |
|
| 324 | - | if bh < 3 { return 1; } |
|
| 325 | - | if bh > 7 { return 2; } |
|
| 324 | + | assert bh >= 3; |
|
| 325 | + | assert bh <= 7; |
|
| 326 | 326 | ||
| 327 | 327 | return 0; |
|
| 328 | 328 | } |
|
| 329 | 329 | ||
| 330 | 330 | @default fn main() -> i32 { |
lib/std/arch/rv64/tests/prog.regex.rad
+17 -17
| 273 | 273 | } |
|
| 274 | 274 | ||
| 275 | 275 | fn testLiteral(nfa: *mut NfaState) -> i32 { |
|
| 276 | 276 | let start: u32 = compile(nfa, "abc"); |
|
| 277 | 277 | ||
| 278 | - | if not nfaMatches(nfa, start, "abc") { return 1; } |
|
| 278 | + | assert nfaMatches(nfa, start, "abc"); |
|
| 279 | 279 | if nfaMatches(nfa, start, "ab") { return 2; } |
|
| 280 | 280 | if nfaMatches(nfa, start, "abcd") { return 3; } |
|
| 281 | 281 | if nfaMatches(nfa, start, "abd") { return 4; } |
|
| 282 | 282 | ||
| 283 | 283 | return 0; |
|
| 284 | 284 | } |
|
| 285 | 285 | ||
| 286 | 286 | fn testStar(nfa: *mut NfaState) -> i32 { |
|
| 287 | 287 | let start: u32 = compile(nfa, "a*"); |
|
| 288 | 288 | ||
| 289 | - | if not nfaMatches(nfa, start, "") { return 1; } |
|
| 290 | - | if not nfaMatches(nfa, start, "a") { return 2; } |
|
| 291 | - | if not nfaMatches(nfa, start, "aaa") { return 3; } |
|
| 289 | + | assert nfaMatches(nfa, start, ""); |
|
| 290 | + | assert nfaMatches(nfa, start, "a"); |
|
| 291 | + | assert nfaMatches(nfa, start, "aaa"); |
|
| 292 | 292 | if nfaMatches(nfa, start, "b") { return 4; } |
|
| 293 | 293 | ||
| 294 | 294 | return 0; |
|
| 295 | 295 | } |
|
| 296 | 296 | ||
| 297 | 297 | fn testPlus(nfa: *mut NfaState) -> i32 { |
|
| 298 | 298 | let start: u32 = compile(nfa, "a+"); |
|
| 299 | 299 | ||
| 300 | 300 | if nfaMatches(nfa, start, "") { return 1; } |
|
| 301 | - | if not nfaMatches(nfa, start, "a") { return 2; } |
|
| 302 | - | if not nfaMatches(nfa, start, "aaaaa") { return 3; } |
|
| 301 | + | assert nfaMatches(nfa, start, "a"); |
|
| 302 | + | assert nfaMatches(nfa, start, "aaaaa"); |
|
| 303 | 303 | ||
| 304 | 304 | return 0; |
|
| 305 | 305 | } |
|
| 306 | 306 | ||
| 307 | 307 | fn testQuestion(nfa: *mut NfaState) -> i32 { |
|
| 308 | 308 | let start: u32 = compile(nfa, "a?"); |
|
| 309 | 309 | ||
| 310 | - | if not nfaMatches(nfa, start, "") { return 1; } |
|
| 311 | - | if not nfaMatches(nfa, start, "a") { return 2; } |
|
| 310 | + | assert nfaMatches(nfa, start, ""); |
|
| 311 | + | assert nfaMatches(nfa, start, "a"); |
|
| 312 | 312 | if nfaMatches(nfa, start, "aa") { return 3; } |
|
| 313 | 313 | ||
| 314 | 314 | return 0; |
|
| 315 | 315 | } |
|
| 316 | 316 | ||
| 317 | 317 | fn testDot(nfa: *mut NfaState) -> i32 { |
|
| 318 | 318 | let start: u32 = compile(nfa, ".."); |
|
| 319 | 319 | ||
| 320 | - | if not nfaMatches(nfa, start, "ab") { return 1; } |
|
| 321 | - | if not nfaMatches(nfa, start, "zz") { return 2; } |
|
| 320 | + | assert nfaMatches(nfa, start, "ab"); |
|
| 321 | + | assert nfaMatches(nfa, start, "zz"); |
|
| 322 | 322 | if nfaMatches(nfa, start, "a") { return 3; } |
|
| 323 | 323 | if nfaMatches(nfa, start, "abc") { return 4; } |
|
| 324 | 324 | ||
| 325 | 325 | return 0; |
|
| 326 | 326 | } |
|
| 327 | 327 | ||
| 328 | 328 | fn testComplex(nfa: *mut NfaState) -> i32 { |
|
| 329 | 329 | let start: u32 = compile(nfa, "ab*c"); |
|
| 330 | 330 | ||
| 331 | - | if not nfaMatches(nfa, start, "ac") { return 1; } |
|
| 332 | - | if not nfaMatches(nfa, start, "abc") { return 2; } |
|
| 333 | - | if not nfaMatches(nfa, start, "abbc") { return 3; } |
|
| 334 | - | if not nfaMatches(nfa, start, "abbbc") { return 4; } |
|
| 331 | + | assert nfaMatches(nfa, start, "ac"); |
|
| 332 | + | assert nfaMatches(nfa, start, "abc"); |
|
| 333 | + | assert nfaMatches(nfa, start, "abbc"); |
|
| 334 | + | assert nfaMatches(nfa, start, "abbbc"); |
|
| 335 | 335 | if nfaMatches(nfa, start, "a") { return 5; } |
|
| 336 | 336 | if nfaMatches(nfa, start, "adc") { return 6; } |
|
| 337 | 337 | ||
| 338 | 338 | return 0; |
|
| 339 | 339 | } |
|
| 340 | 340 | ||
| 341 | 341 | fn testDotStar(nfa: *mut NfaState) -> i32 { |
|
| 342 | 342 | let start: u32 = compile(nfa, ".*"); |
|
| 343 | 343 | ||
| 344 | - | if not nfaMatches(nfa, start, "") { return 1; } |
|
| 345 | - | if not nfaMatches(nfa, start, "hello") { return 2; } |
|
| 346 | - | if not nfaMatches(nfa, start, "x") { return 3; } |
|
| 344 | + | assert nfaMatches(nfa, start, ""); |
|
| 345 | + | assert nfaMatches(nfa, start, "hello"); |
|
| 346 | + | assert nfaMatches(nfa, start, "x"); |
|
| 347 | 347 | ||
| 348 | 348 | return 0; |
|
| 349 | 349 | } |
|
| 350 | 350 | ||
| 351 | 351 | @default fn main() -> i32 { |
lib/std/arch/rv64/tests/prog.sha256.rad
+24 -68
| 157 | 157 | } |
|
| 158 | 158 | ||
| 159 | 159 | /// Test SHA-256 of the empty string "". |
|
| 160 | 160 | /// Expected: e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 |
|
| 161 | 161 | fn testEmpty(s: *mut Sha256, k: *[u32]) -> i32 { |
|
| 162 | - | if hashMessage(s, k, &[]) != 0 { |
|
| 163 | - | return 1; |
|
| 164 | - | } |
|
| 165 | - | ||
| 166 | - | if s.h[0] != 0xE3B0C442 { |
|
| 167 | - | return 2; |
|
| 168 | - | } |
|
| 169 | - | if s.h[1] != 0x98FC1C14 { |
|
| 170 | - | return 3; |
|
| 171 | - | } |
|
| 172 | - | if s.h[2] != 0x9AFBF4C8 { |
|
| 173 | - | return 4; |
|
| 174 | - | } |
|
| 175 | - | if s.h[3] != 0x996FB924 { |
|
| 176 | - | return 5; |
|
| 177 | - | } |
|
| 178 | - | if s.h[4] != 0x27AE41E4 { |
|
| 179 | - | return 6; |
|
| 180 | - | } |
|
| 181 | - | if s.h[5] != 0x649B934C { |
|
| 182 | - | return 7; |
|
| 183 | - | } |
|
| 184 | - | if s.h[6] != 0xA495991B { |
|
| 185 | - | return 8; |
|
| 186 | - | } |
|
| 187 | - | if s.h[7] != 0x7852B855 { |
|
| 188 | - | return 9; |
|
| 189 | - | } |
|
| 162 | + | assert hashMessage(s, k, &[]) == 0; |
|
| 163 | + | ||
| 164 | + | assert s.h[0] == 0xE3B0C442; |
|
| 165 | + | assert s.h[1] == 0x98FC1C14; |
|
| 166 | + | assert s.h[2] == 0x9AFBF4C8; |
|
| 167 | + | assert s.h[3] == 0x996FB924; |
|
| 168 | + | assert s.h[4] == 0x27AE41E4; |
|
| 169 | + | assert s.h[5] == 0x649B934C; |
|
| 170 | + | assert s.h[6] == 0xA495991B; |
|
| 171 | + | assert s.h[7] == 0x7852B855; |
|
| 190 | 172 | return 0; |
|
| 191 | 173 | } |
|
| 192 | 174 | ||
| 193 | 175 | /// Test SHA-256 of "abc". |
|
| 194 | 176 | /// Expected: ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad |
|
| 195 | 177 | fn testAbc(s: *mut Sha256, k: *[u32]) -> i32 { |
|
| 196 | 178 | let msg: [u8; 3] = [0x61, 0x62, 0x63]; |
|
| 197 | - | if hashMessage(s, k, &msg[..]) != 0 { |
|
| 198 | - | return 1; |
|
| 199 | - | } |
|
| 200 | - | ||
| 201 | - | if s.h[0] != 0xBA7816BF { |
|
| 202 | - | return 2; |
|
| 203 | - | } |
|
| 204 | - | if s.h[1] != 0x8F01CFEA { |
|
| 205 | - | return 3; |
|
| 206 | - | } |
|
| 207 | - | if s.h[2] != 0x414140DE { |
|
| 208 | - | return 4; |
|
| 209 | - | } |
|
| 210 | - | if s.h[3] != 0x5DAE2223 { |
|
| 211 | - | return 5; |
|
| 212 | - | } |
|
| 213 | - | if s.h[4] != 0xB00361A3 { |
|
| 214 | - | return 6; |
|
| 215 | - | } |
|
| 216 | - | if s.h[5] != 0x96177A9C { |
|
| 217 | - | return 7; |
|
| 218 | - | } |
|
| 219 | - | if s.h[6] != 0xB410FF61 { |
|
| 220 | - | return 8; |
|
| 221 | - | } |
|
| 222 | - | if s.h[7] != 0xF20015AD { |
|
| 223 | - | return 9; |
|
| 224 | - | } |
|
| 179 | + | assert hashMessage(s, k, &msg[..]) == 0; |
|
| 180 | + | ||
| 181 | + | assert s.h[0] == 0xBA7816BF; |
|
| 182 | + | assert s.h[1] == 0x8F01CFEA; |
|
| 183 | + | assert s.h[2] == 0x414140DE; |
|
| 184 | + | assert s.h[3] == 0x5DAE2223; |
|
| 185 | + | assert s.h[4] == 0xB00361A3; |
|
| 186 | + | assert s.h[5] == 0x96177A9C; |
|
| 187 | + | assert s.h[6] == 0xB410FF61; |
|
| 188 | + | assert s.h[7] == 0xF20015AD; |
|
| 225 | 189 | return 0; |
|
| 226 | 190 | } |
|
| 227 | 191 | ||
| 228 | 192 | /// Test the helper functions directly. |
|
| 229 | 193 | fn testHelpers() -> i32 { |
|
| 230 | 194 | // rotr(1, 1) should be 0x80000000 |
|
| 231 | - | if rotr(1, 1) != 0x80000000 { |
|
| 232 | - | return 1; |
|
| 233 | - | } |
|
| 195 | + | assert rotr(1, 1) == 0x80000000; |
|
| 234 | 196 | // rotr(0xFF000000, 8) should be 0x00FF0000 |
|
| 235 | - | if rotr(0xFF000000, 8) != 0x00FF0000 { |
|
| 236 | - | return 2; |
|
| 237 | - | } |
|
| 197 | + | assert rotr(0xFF000000, 8) == 0x00FF0000; |
|
| 238 | 198 | // ch(0xFF, 0x0F, 0xF0): |
|
| 239 | 199 | // 0xFF & 0x0F = 0x0F |
|
| 240 | 200 | // ~0xFF = 0xFFFFFF00, & 0xF0 = 0x00 |
|
| 241 | 201 | // result = 0x0F ^ 0x00 = 0x0F |
|
| 242 | - | if ch(0xFF, 0x0F, 0xF0) != 0x0F { |
|
| 243 | - | return 3; |
|
| 244 | - | } |
|
| 202 | + | assert ch(0xFF, 0x0F, 0xF0) == 0x0F; |
|
| 245 | 203 | // maj(0xFF, 0x0F, 0xF0): |
|
| 246 | 204 | // 0xFF & 0x0F = 0x0F |
|
| 247 | 205 | // 0xFF & 0xF0 = 0xF0 |
|
| 248 | 206 | // 0x0F & 0xF0 = 0x00 |
|
| 249 | 207 | // result = 0x0F ^ 0xF0 ^ 0x00 = 0xFF |
|
| 250 | - | if maj(0xFF, 0x0F, 0xF0) != 0xFF { |
|
| 251 | - | return 4; |
|
| 252 | - | } |
|
| 208 | + | assert maj(0xFF, 0x0F, 0xF0) == 0xFF; |
|
| 253 | 209 | return 0; |
|
| 254 | 210 | } |
|
| 255 | 211 | ||
| 256 | 212 | @default fn main() -> i32 { |
|
| 257 | 213 | // SHA-256 round constants (first 32 bits of fractional parts of cube roots |
lib/std/arch/rv64/tests/prog.sieve.rad
+8 -24
| 61 | 61 | } |
|
| 62 | 62 | } |
|
| 63 | 63 | // Known small composites. |
|
| 64 | 64 | let composites: [u32; 5] = [4, 6, 8, 9, 10]; |
|
| 65 | 65 | for c in composites { |
|
| 66 | - | if not sieve[c] { |
|
| 67 | - | return 7; |
|
| 68 | - | } |
|
| 66 | + | assert sieve[c]; |
|
| 69 | 67 | } |
|
| 70 | 68 | // Larger primes. |
|
| 71 | 69 | if sieve[97] { |
|
| 72 | 70 | return 12; |
|
| 73 | 71 | } |
|
| 74 | 72 | if sieve[251] { |
|
| 75 | 73 | return 13; |
|
| 76 | 74 | } |
|
| 77 | 75 | // Larger composites. |
|
| 78 | - | if not sieve[100] { |
|
| 79 | - | return 14; |
|
| 80 | - | } |
|
| 81 | - | if not sieve[250] { |
|
| 82 | - | return 15; |
|
| 83 | - | } |
|
| 76 | + | assert sieve[100]; |
|
| 77 | + | assert sieve[250]; |
|
| 84 | 78 | return 0; |
|
| 85 | 79 | } |
|
| 86 | 80 | ||
| 87 | 81 | /// Verify that collected primes are in ascending order and all valid. |
|
| 88 | 82 | fn verifyCollected(sieve: *[bool]) -> i32 { |
|
| 89 | 83 | let mut primesBuf: [u32; 64] = [0; 64]; |
|
| 90 | 84 | let count = collectPrimes(sieve, &mut primesBuf[..]); |
|
| 91 | 85 | ||
| 92 | - | if count != 54 { |
|
| 93 | - | return 1; |
|
| 94 | - | } |
|
| 86 | + | assert count == 54; |
|
| 95 | 87 | ||
| 96 | 88 | // First prime should be 2. |
|
| 97 | - | if primesBuf[0] != 2 { |
|
| 98 | - | return 2; |
|
| 99 | - | } |
|
| 89 | + | assert primesBuf[0] == 2; |
|
| 100 | 90 | // Last prime should be 251. |
|
| 101 | - | if primesBuf[count - 1] != 251 { |
|
| 102 | - | return 3; |
|
| 103 | - | } |
|
| 91 | + | assert primesBuf[count - 1] == 251; |
|
| 104 | 92 | ||
| 105 | 93 | // Verify ascending order. |
|
| 106 | 94 | let collected = &primesBuf[0..count]; |
|
| 107 | 95 | let mut prev: ?u32 = nil; |
|
| 108 | 96 | for p in collected { |
|
| 109 | 97 | if let prevVal = prev { |
|
| 110 | - | if prevVal >= p { |
|
| 111 | - | return 4; |
|
| 112 | - | } |
|
| 98 | + | assert prevVal < p; |
|
| 113 | 99 | } |
|
| 114 | 100 | prev = p; |
|
| 115 | 101 | } |
|
| 116 | 102 | return 0; |
|
| 117 | 103 | } |
| 124 | 110 | if r1 != 0 { |
|
| 125 | 111 | return 10 + r1; |
|
| 126 | 112 | } |
|
| 127 | 113 | ||
| 128 | 114 | // There are 54 primes <= 255 (2, 3, 5, ..., 251). |
|
| 129 | - | if countPrimes(&sieve[..]) != 54 { |
|
| 130 | - | return 30; |
|
| 131 | - | } |
|
| 115 | + | assert countPrimes(&sieve[..]) == 54; |
|
| 132 | 116 | ||
| 133 | 117 | let r3 = verifyCollected(&sieve[..]); |
|
| 134 | 118 | if r3 != 0 { |
|
| 135 | 119 | return 40 + r3; |
|
| 136 | 120 | } |
lib/std/arch/rv64/tests/prog.symtab.rad
+15 -43
| 167 | 167 | define(tab, "z", 30); |
|
| 168 | 168 | ||
| 169 | 169 | let x = lookup(tab, "x") else { |
|
| 170 | 170 | return 1; |
|
| 171 | 171 | }; |
|
| 172 | - | if x != 10 { |
|
| 173 | - | return 2; |
|
| 174 | - | } |
|
| 172 | + | assert x == 10; |
|
| 175 | 173 | ||
| 176 | 174 | let y = lookup(tab, "y") else { |
|
| 177 | 175 | return 3; |
|
| 178 | 176 | }; |
|
| 179 | - | if y != 20 { |
|
| 180 | - | return 4; |
|
| 181 | - | } |
|
| 177 | + | assert y == 20; |
|
| 182 | 178 | ||
| 183 | 179 | let z = lookup(tab, "z") else { |
|
| 184 | 180 | return 5; |
|
| 185 | 181 | }; |
|
| 186 | - | if z != 30 { |
|
| 187 | - | return 6; |
|
| 188 | - | } |
|
| 182 | + | assert z == 30; |
|
| 189 | 183 | ||
| 190 | 184 | // Lookup nonexistent symbol. |
|
| 191 | 185 | if let val = lookup(tab, "w") { |
|
| 192 | 186 | return 7; |
|
| 193 | 187 | } |
| 204 | 198 | ||
| 205 | 199 | // Verify outer x. |
|
| 206 | 200 | let x1 = lookup(tab, "x") else { |
|
| 207 | 201 | return 1; |
|
| 208 | 202 | }; |
|
| 209 | - | if x1 != 1 { |
|
| 210 | - | return 2; |
|
| 211 | - | } |
|
| 203 | + | assert x1 == 1; |
|
| 212 | 204 | ||
| 213 | 205 | // Push inner scope, shadow x. |
|
| 214 | 206 | pushScope(tab); |
|
| 215 | 207 | define(tab, "x", 2); |
|
| 216 | 208 | ||
| 217 | 209 | let x2 = lookup(tab, "x") else { |
|
| 218 | 210 | return 3; |
|
| 219 | 211 | }; |
|
| 220 | - | if x2 != 2 { |
|
| 221 | - | return 4; |
|
| 222 | - | } |
|
| 212 | + | assert x2 == 2; |
|
| 223 | 213 | ||
| 224 | 214 | // Pop inner scope, x should revert. |
|
| 225 | 215 | popScope(tab); |
|
| 226 | 216 | ||
| 227 | 217 | let x3 = lookup(tab, "x") else { |
|
| 228 | 218 | return 5; |
|
| 229 | 219 | }; |
|
| 230 | - | if x3 != 1 { |
|
| 231 | - | return 6; |
|
| 232 | - | } |
|
| 220 | + | assert x3 == 1; |
|
| 233 | 221 | ||
| 234 | 222 | popScope(tab); |
|
| 235 | 223 | return 0; |
|
| 236 | 224 | } |
|
| 237 | 225 |
| 249 | 237 | ||
| 250 | 238 | // x should be the innermost value. |
|
| 251 | 239 | let x = lookup(tab, "x") else { |
|
| 252 | 240 | return 1; |
|
| 253 | 241 | }; |
|
| 254 | - | if x != 70 { |
|
| 255 | - | return 2; |
|
| 256 | - | } |
|
| 242 | + | assert x == 70; |
|
| 257 | 243 | ||
| 258 | 244 | // Pop scopes one by one and check. |
|
| 259 | 245 | i = 7; |
|
| 260 | 246 | while i > 0 { |
|
| 261 | 247 | popScope(tab); |
|
| 262 | 248 | let val = lookup(tab, "x") else { |
|
| 263 | 249 | return 3; |
|
| 264 | 250 | }; |
|
| 265 | 251 | let expected = (i - 1) as i32 * 10; |
|
| 266 | - | if val != expected { |
|
| 267 | - | return 4; |
|
| 268 | - | } |
|
| 252 | + | assert val == expected; |
|
| 269 | 253 | i -= 1; |
|
| 270 | 254 | } |
|
| 271 | 255 | ||
| 272 | 256 | popScope(tab); |
|
| 273 | 257 | return 0; |
| 295 | 279 | return 1; |
|
| 296 | 280 | } |
|
| 297 | 281 | } |
|
| 298 | 282 | ||
| 299 | 283 | // 1+2+3+4+5+6+7+8 = 36 |
|
| 300 | - | if sum != 36 { |
|
| 301 | - | return 2; |
|
| 302 | - | } |
|
| 284 | + | assert sum == 36; |
|
| 303 | 285 | ||
| 304 | 286 | popScope(tab); |
|
| 305 | 287 | return 0; |
|
| 306 | 288 | } |
|
| 307 | 289 |
| 316 | 298 | let mut i: u32 = 0; |
|
| 317 | 299 | while i < 10 { |
|
| 318 | 300 | let cur = lookup(tab, "counter") else { |
|
| 319 | 301 | return 1; |
|
| 320 | 302 | }; |
|
| 321 | - | if not update(tab, "counter", cur + 1) { |
|
| 322 | - | return 2; |
|
| 323 | - | } |
|
| 303 | + | assert update(tab, "counter", cur + 1); |
|
| 324 | 304 | i += 1; |
|
| 325 | 305 | } |
|
| 326 | 306 | ||
| 327 | - | let final_val = lookup(tab, "counter") else { |
|
| 307 | + | let finalVal = lookup(tab, "counter") else { |
|
| 328 | 308 | return 3; |
|
| 329 | 309 | }; |
|
| 330 | - | if final_val != 10 { |
|
| 331 | - | return 4; |
|
| 332 | - | } |
|
| 310 | + | assert finalVal == 10; |
|
| 333 | 311 | ||
| 334 | 312 | // Update nonexistent symbol should fail. |
|
| 335 | 313 | if update(tab, "nonexistent", 99) { |
|
| 336 | 314 | return 5; |
|
| 337 | 315 | } |
| 350 | 328 | pushScope(tab); |
|
| 351 | 329 | define(tab, "inner", 2); |
|
| 352 | 330 | ||
| 353 | 331 | // Both visible. |
|
| 354 | 332 | if let val = lookup(tab, "outer") { |
|
| 355 | - | if val != 1 { |
|
| 356 | - | return 1; |
|
| 357 | - | } |
|
| 333 | + | assert val == 1; |
|
| 358 | 334 | } else { |
|
| 359 | 335 | return 2; |
|
| 360 | 336 | } |
|
| 361 | 337 | if let val = lookup(tab, "inner") { |
|
| 362 | - | if val != 2 { |
|
| 363 | - | return 3; |
|
| 364 | - | } |
|
| 338 | + | assert val == 2; |
|
| 365 | 339 | } else { |
|
| 366 | 340 | return 4; |
|
| 367 | 341 | } |
|
| 368 | 342 | ||
| 369 | 343 | popScope(tab); |
|
| 370 | 344 | ||
| 371 | 345 | // outer still visible, inner gone. |
|
| 372 | 346 | if let val = lookup(tab, "outer") { |
|
| 373 | - | if val != 1 { |
|
| 374 | - | return 5; |
|
| 375 | - | } |
|
| 347 | + | assert val == 1; |
|
| 376 | 348 | } else { |
|
| 377 | 349 | return 6; |
|
| 378 | 350 | } |
|
| 379 | 351 | if let val = lookup(tab, "inner") { |
|
| 380 | 352 | return 7; |
lib/std/arch/rv64/tests/prog.tokenizer.rad
+14 -42
| 368 | 368 | /// Test simple number. |
|
| 369 | 369 | fn testNumber(tokenBuf: *mut [Token], exprBuf: *mut [Expr]) -> i32 { |
|
| 370 | 370 | let result = evaluate("42", tokenBuf, exprBuf) else { |
|
| 371 | 371 | return 1; |
|
| 372 | 372 | }; |
|
| 373 | - | if result != 42 { |
|
| 374 | - | return 2; |
|
| 375 | - | } |
|
| 373 | + | assert result == 42; |
|
| 376 | 374 | return 0; |
|
| 377 | 375 | } |
|
| 378 | 376 | ||
| 379 | 377 | /// Test addition. |
|
| 380 | 378 | fn testAdd(tokenBuf: *mut [Token], exprBuf: *mut [Expr]) -> i32 { |
|
| 381 | 379 | let result = evaluate("3 + 4", tokenBuf, exprBuf) else { |
|
| 382 | 380 | return 1; |
|
| 383 | 381 | }; |
|
| 384 | - | if result != 7 { |
|
| 385 | - | return 2; |
|
| 386 | - | } |
|
| 382 | + | assert result == 7; |
|
| 387 | 383 | return 0; |
|
| 388 | 384 | } |
|
| 389 | 385 | ||
| 390 | 386 | /// Test precedence: multiplication before addition. |
|
| 391 | 387 | fn testPrecedence(tokenBuf: *mut [Token], exprBuf: *mut [Expr]) -> i32 { |
|
| 392 | 388 | let result = evaluate("2 + 3 * 4", tokenBuf, exprBuf) else { |
|
| 393 | 389 | return 1; |
|
| 394 | 390 | }; |
|
| 395 | - | if result != 14 { |
|
| 396 | - | return 2; |
|
| 397 | - | } |
|
| 391 | + | assert result == 14; |
|
| 398 | 392 | return 0; |
|
| 399 | 393 | } |
|
| 400 | 394 | ||
| 401 | 395 | /// Test parenthesized expression. |
|
| 402 | 396 | fn testParens(tokenBuf: *mut [Token], exprBuf: *mut [Expr]) -> i32 { |
|
| 403 | 397 | let result = evaluate("(2 + 3) * 4", tokenBuf, exprBuf) else { |
|
| 404 | 398 | return 1; |
|
| 405 | 399 | }; |
|
| 406 | - | if result != 20 { |
|
| 407 | - | return 2; |
|
| 408 | - | } |
|
| 400 | + | assert result == 20; |
|
| 409 | 401 | return 0; |
|
| 410 | 402 | } |
|
| 411 | 403 | ||
| 412 | 404 | /// Test negation. |
|
| 413 | 405 | fn testNeg(tokenBuf: *mut [Token], exprBuf: *mut [Expr]) -> i32 { |
|
| 414 | 406 | let result = evaluate("-5 + 8", tokenBuf, exprBuf) else { |
|
| 415 | 407 | return 1; |
|
| 416 | 408 | }; |
|
| 417 | - | if result != 3 { |
|
| 418 | - | return 2; |
|
| 419 | - | } |
|
| 409 | + | assert result == 3; |
|
| 420 | 410 | return 0; |
|
| 421 | 411 | } |
|
| 422 | 412 | ||
| 423 | 413 | /// Test complex expression. |
|
| 424 | 414 | fn testComplex(tokenBuf: *mut [Token], exprBuf: *mut [Expr]) -> i32 { |
|
| 425 | 415 | // (10 - 3) * (2 + 1) = 7 * 3 = 21 |
|
| 426 | 416 | let result = evaluate("(10 - 3) * (2 + 1)", tokenBuf, exprBuf) else { |
|
| 427 | 417 | return 1; |
|
| 428 | 418 | }; |
|
| 429 | - | if result != 21 { |
|
| 430 | - | return 2; |
|
| 431 | - | } |
|
| 419 | + | assert result == 21; |
|
| 432 | 420 | return 0; |
|
| 433 | 421 | } |
|
| 434 | 422 | ||
| 435 | 423 | /// Test chained operations. |
|
| 436 | 424 | fn testChained(tokenBuf: *mut [Token], exprBuf: *mut [Expr]) -> i32 { |
|
| 437 | 425 | // 100 - 20 - 30 - 10 = 40 |
|
| 438 | 426 | let result = evaluate("100 - 20 - 30 - 10", tokenBuf, exprBuf) else { |
|
| 439 | 427 | return 1; |
|
| 440 | 428 | }; |
|
| 441 | - | if result != 40 { |
|
| 442 | - | return 2; |
|
| 443 | - | } |
|
| 429 | + | assert result == 40; |
|
| 444 | 430 | return 0; |
|
| 445 | 431 | } |
|
| 446 | 432 | ||
| 447 | 433 | /// Test token counting via for-in. |
|
| 448 | 434 | fn testTokenCount(tokenBuf: *mut [Token], exprBuf: *mut [Expr]) -> i32 { |
|
| 449 | 435 | let mut lex = Lexer { source: "1 + 2 * 3", pos: 0 }; |
|
| 450 | 436 | let mut list = TokenList { tokens: tokenBuf, count: 0 }; |
|
| 451 | - | if not tokenize(&mut lex, &mut list) { |
|
| 452 | - | return 1; |
|
| 453 | - | } |
|
| 437 | + | assert tokenize(&mut lex, &mut list); |
|
| 454 | 438 | ||
| 455 | 439 | // Should be: 1, +, 2, *, 3, Eof = 6 tokens |
|
| 456 | - | if list.count != 6 { |
|
| 457 | - | return 2; |
|
| 458 | - | } |
|
| 440 | + | assert list.count == 6; |
|
| 459 | 441 | ||
| 460 | 442 | // Count number tokens using for-in. |
|
| 461 | 443 | let mut numCount: u32 = 0; |
|
| 462 | 444 | let slice = &tokenBuf[0..list.count]; |
|
| 463 | 445 | for tok in slice { |
| 466 | 448 | numCount += 1; |
|
| 467 | 449 | } |
|
| 468 | 450 | else => {} |
|
| 469 | 451 | } |
|
| 470 | 452 | } |
|
| 471 | - | if numCount != 3 { |
|
| 472 | - | return 3; |
|
| 473 | - | } |
|
| 453 | + | assert numCount == 3; |
|
| 474 | 454 | ||
| 475 | 455 | return 0; |
|
| 476 | 456 | } |
|
| 477 | 457 | ||
| 478 | 458 | /// Test division and mixed operations. |
|
| 479 | 459 | fn testDivision(tokenBuf: *mut [Token], exprBuf: *mut [Expr]) -> i32 { |
|
| 480 | 460 | // 20 / 4 + 3 = 5 + 3 = 8 |
|
| 481 | 461 | let result = evaluate("20 / 4 + 3", tokenBuf, exprBuf) else { |
|
| 482 | 462 | return 1; |
|
| 483 | 463 | }; |
|
| 484 | - | if result != 8 { |
|
| 485 | - | return 2; |
|
| 486 | - | } |
|
| 464 | + | assert result == 8; |
|
| 487 | 465 | return 0; |
|
| 488 | 466 | } |
|
| 489 | 467 | ||
| 490 | 468 | /// Test deeply nested parentheses. |
|
| 491 | 469 | fn testDeepNesting(tokenBuf: *mut [Token], exprBuf: *mut [Expr]) -> i32 { |
|
| 492 | 470 | // ((((5)))) = 5 |
|
| 493 | 471 | let result = evaluate("((((5))))", tokenBuf, exprBuf) else { |
|
| 494 | 472 | return 1; |
|
| 495 | 473 | }; |
|
| 496 | - | if result != 5 { |
|
| 497 | - | return 2; |
|
| 498 | - | } |
|
| 474 | + | assert result == 5; |
|
| 499 | 475 | return 0; |
|
| 500 | 476 | } |
|
| 501 | 477 | ||
| 502 | 478 | /// Test node count of complex expression. |
|
| 503 | 479 | fn testNodeCount(tokenBuf: *mut [Token], exprBuf: *mut [Expr]) -> i32 { |
|
| 504 | 480 | let mut lex = Lexer { source: "1 + 2 * 3", pos: 0 }; |
|
| 505 | 481 | let mut list = TokenList { tokens: tokenBuf, count: 0 }; |
|
| 506 | - | if not tokenize(&mut lex, &mut list) { |
|
| 507 | - | return 1; |
|
| 508 | - | } |
|
| 482 | + | assert tokenize(&mut lex, &mut list); |
|
| 509 | 483 | ||
| 510 | 484 | let mut pool = ExprPool { nodes: exprBuf, count: 0 }; |
|
| 511 | 485 | let mut parser = Parser { |
|
| 512 | 486 | tokens: tokenBuf, |
|
| 513 | 487 | tokenCount: list.count, |
| 519 | 493 | return 2; |
|
| 520 | 494 | }; |
|
| 521 | 495 | ||
| 522 | 496 | // 1 + (2 * 3) = 5 nodes: Num(1), Num(2), Num(3), BinOp(*), BinOp(+) |
|
| 523 | 497 | let count = countNodes(exprBuf, root); |
|
| 524 | - | if count != 5 { |
|
| 525 | - | return 3; |
|
| 526 | - | } |
|
| 498 | + | assert count == 5; |
|
| 527 | 499 | return 0; |
|
| 528 | 500 | } |
|
| 529 | 501 | ||
| 530 | 502 | @default fn main() -> i32 { |
|
| 531 | 503 | let mut tokenBuf: [Token; 128] = [Token::Eof; 128]; |
lib/std/arch/rv64/tests/prog.vm.rad
+13 -39
| 264 | 264 | code[3] = Op::Mul; |
|
| 265 | 265 | code[4] = Op::Add; |
|
| 266 | 266 | code[5] = Op::Halt; |
|
| 267 | 267 | ||
| 268 | 268 | let result: i32 = try! runProgram(&code[..], 6, stackBuf, localsBuf, framesBuf); |
|
| 269 | - | if result != 11 { |
|
| 270 | - | return 1; |
|
| 271 | - | } |
|
| 269 | + | assert result == 11; |
|
| 272 | 270 | return 0; |
|
| 273 | 271 | } |
|
| 274 | 272 | ||
| 275 | 273 | /// Test local variables: x = 5, y = 7, push x + y. |
|
| 276 | 274 | fn testLocals(stackBuf: *mut [i32], localsBuf: *mut [i32], framesBuf: *mut [Frame]) -> i32 { |
| 283 | 281 | code[5] = Op::Load(1); // push y |
|
| 284 | 282 | code[6] = Op::Add; // x + y |
|
| 285 | 283 | code[7] = Op::Halt; |
|
| 286 | 284 | ||
| 287 | 285 | let result: i32 = try! runProgram(&code[..], 8, stackBuf, localsBuf, framesBuf); |
|
| 288 | - | if result != 12 { |
|
| 289 | - | return 1; |
|
| 290 | - | } |
|
| 286 | + | assert result == 12; |
|
| 291 | 287 | return 0; |
|
| 292 | 288 | } |
|
| 293 | 289 | ||
| 294 | 290 | /// Test conditional jump: if 3 > 2 then push 42 else push 99. |
|
| 295 | 291 | fn testConditional(stackBuf: *mut [i32], localsBuf: *mut [i32], framesBuf: *mut [Frame]) -> i32 { |
| 302 | 298 | code[5] = Op::Jump(7); // skip false branch |
|
| 303 | 299 | code[6] = Op::Push(99); // false branch |
|
| 304 | 300 | code[7] = Op::Halt; |
|
| 305 | 301 | ||
| 306 | 302 | let result: i32 = try! runProgram(&code[..], 8, stackBuf, localsBuf, framesBuf); |
|
| 307 | - | if result != 42 { |
|
| 308 | - | return 1; |
|
| 309 | - | } |
|
| 303 | + | assert result == 42; |
|
| 310 | 304 | return 0; |
|
| 311 | 305 | } |
|
| 312 | 306 | ||
| 313 | 307 | /// Test loop: sum 1..5 using jumps. |
|
| 314 | 308 | /// local[0] = counter (starts at 1), local[1] = sum (starts at 0). |
| 335 | 329 | code[17] = Op::Load(1); // push sum |
|
| 336 | 330 | code[18] = Op::Halt; |
|
| 337 | 331 | ||
| 338 | 332 | let result: i32 = try! runProgram(&code[..], 19, stackBuf, localsBuf, framesBuf); |
|
| 339 | 333 | // sum = 1+2+3+4+5 = 15 |
|
| 340 | - | if result != 15 { |
|
| 341 | - | return 1; |
|
| 342 | - | } |
|
| 334 | + | assert result == 15; |
|
| 343 | 335 | return 0; |
|
| 344 | 336 | } |
|
| 345 | 337 | ||
| 346 | 338 | /// Test function call: call a function that computes n*2+1 for n=10. |
|
| 347 | 339 | fn testCall(stackBuf: *mut [i32], localsBuf: *mut [i32], framesBuf: *mut [Frame]) -> i32 { |
| 364 | 356 | code[10] = Op::Add; // n * 2 + 1 |
|
| 365 | 357 | code[11] = Op::Ret; // return (result on stack) |
|
| 366 | 358 | ||
| 367 | 359 | let result: i32 = try! runProgram(&code[..], 12, stackBuf, localsBuf, framesBuf); |
|
| 368 | 360 | // 10 * 2 + 1 = 21 |
|
| 369 | - | if result != 21 { |
|
| 370 | - | return 1; |
|
| 371 | - | } |
|
| 361 | + | assert result == 21; |
|
| 372 | 362 | return 0; |
|
| 373 | 363 | } |
|
| 374 | 364 | ||
| 375 | 365 | /// Test division by zero detection using try...catch with error binding. |
|
| 376 | 366 | fn testDivByZero(stackBuf: *mut [i32], localsBuf: *mut [i32], framesBuf: *mut [Frame]) -> i32 { |
| 386 | 376 | caught = 1; |
|
| 387 | 377 | } else { |
|
| 388 | 378 | caught = 2; |
|
| 389 | 379 | } |
|
| 390 | 380 | }; |
|
| 391 | - | if caught != 1 { |
|
| 392 | - | return 1; |
|
| 393 | - | } |
|
| 381 | + | assert caught == 1; |
|
| 394 | 382 | return 0; |
|
| 395 | 383 | } |
|
| 396 | 384 | ||
| 397 | 385 | /// Test negation and equality. |
|
| 398 | 386 | fn testNegAndEq(stackBuf: *mut [i32], localsBuf: *mut [i32], framesBuf: *mut [Frame]) -> i32 { |
| 402 | 390 | code[2] = Op::Push(-5); |
|
| 403 | 391 | code[3] = Op::Eq; // -5 == -5 => 1 |
|
| 404 | 392 | code[4] = Op::Halt; |
|
| 405 | 393 | ||
| 406 | 394 | let result: i32 = try! runProgram(&code[..], 5, stackBuf, localsBuf, framesBuf); |
|
| 407 | - | if result != 1 { |
|
| 408 | - | return 1; |
|
| 409 | - | } |
|
| 395 | + | assert result == 1; |
|
| 410 | 396 | return 0; |
|
| 411 | 397 | } |
|
| 412 | 398 | ||
| 413 | 399 | /// Test factorial using recursive calls: fact(6) = 720. |
|
| 414 | 400 | fn testFactorial(stackBuf: *mut [i32], localsBuf: *mut [i32], framesBuf: *mut [Frame]) -> i32 { |
| 440 | 426 | code[15] = Op::Load(0); // push n |
|
| 441 | 427 | code[16] = Op::Mul; // fact(n-1) * n |
|
| 442 | 428 | code[17] = Op::Ret; |
|
| 443 | 429 | ||
| 444 | 430 | let result: i32 = try! runProgram(&code[..], 18, stackBuf, localsBuf, framesBuf); |
|
| 445 | - | if result != 720 { |
|
| 446 | - | return 1; |
|
| 447 | - | } |
|
| 431 | + | assert result == 720; |
|
| 448 | 432 | return 0; |
|
| 449 | 433 | } |
|
| 450 | 434 | ||
| 451 | 435 | /// Test dup instruction. |
|
| 452 | 436 | fn testDup(stackBuf: *mut [i32], localsBuf: *mut [i32], framesBuf: *mut [Frame]) -> i32 { |
| 455 | 439 | code[1] = Op::Dup; |
|
| 456 | 440 | code[2] = Op::Add; // 7 + 7 = 14 |
|
| 457 | 441 | code[3] = Op::Halt; |
|
| 458 | 442 | ||
| 459 | 443 | let result: i32 = try! runProgram(&code[..], 4, stackBuf, localsBuf, framesBuf); |
|
| 460 | - | if result != 14 { |
|
| 461 | - | return 1; |
|
| 462 | - | } |
|
| 444 | + | assert result == 14; |
|
| 463 | 445 | return 0; |
|
| 464 | 446 | } |
|
| 465 | 447 | ||
| 466 | 448 | /// Test stack underflow detection using try...catch with error binding. |
|
| 467 | 449 | fn testStackUnderflow(stackBuf: *mut [i32], localsBuf: *mut [i32], framesBuf: *mut [Frame]) -> i32 { |
| 475 | 457 | caught = 1; |
|
| 476 | 458 | } else { |
|
| 477 | 459 | caught = 2; |
|
| 478 | 460 | } |
|
| 479 | 461 | }; |
|
| 480 | - | if caught != 1 { |
|
| 481 | - | return 1; |
|
| 482 | - | } |
|
| 462 | + | assert caught == 1; |
|
| 483 | 463 | return 0; |
|
| 484 | 464 | } |
|
| 485 | 465 | ||
| 486 | 466 | /// Test that try...catch on success path does not execute catch block. |
|
| 487 | 467 | fn testSuccessNoCatch(stackBuf: *mut [i32], localsBuf: *mut [i32], framesBuf: *mut [Frame]) -> i32 { |
| 493 | 473 | let result: i32 = try runProgram(&code[..], 2, stackBuf, localsBuf, framesBuf) catch e { |
|
| 494 | 474 | caught = 1; |
|
| 495 | 475 | return 1; |
|
| 496 | 476 | }; |
|
| 497 | 477 | // Catch block should not have run. |
|
| 498 | - | if caught != 0 { |
|
| 499 | - | return 2; |
|
| 500 | - | } |
|
| 478 | + | assert caught == 0; |
|
| 501 | 479 | // Should have the success value. |
|
| 502 | - | if result != 99 { |
|
| 503 | - | return 3; |
|
| 504 | - | } |
|
| 480 | + | assert result == 99; |
|
| 505 | 481 | return 0; |
|
| 506 | 482 | } |
|
| 507 | 483 | ||
| 508 | 484 | /// Test call overflow detection by exhausting frames. |
|
| 509 | 485 | fn testCallOverflow(stackBuf: *mut [i32], localsBuf: *mut [i32], framesBuf: *mut [Frame]) -> i32 { |
| 518 | 494 | caught = 1; |
|
| 519 | 495 | } else { |
|
| 520 | 496 | caught = 2; |
|
| 521 | 497 | } |
|
| 522 | 498 | }; |
|
| 523 | - | if caught != 1 { |
|
| 524 | - | return 1; |
|
| 525 | - | } |
|
| 499 | + | assert caught == 1; |
|
| 526 | 500 | return 0; |
|
| 527 | 501 | } |
|
| 528 | 502 | ||
| 529 | 503 | /// Test that catch with no binding works (discard the error). |
|
| 530 | 504 | fn testCatchNoBinding(stackBuf: *mut [i32], localsBuf: *mut [i32], framesBuf: *mut [Frame]) -> i32 { |
lib/std/arch/rv64/tests/ptr.eq.rad
+3 -9
| 30 | 30 | ||
| 31 | 31 | return not (a == b); // Different addresses, should NOT be equal. |
|
| 32 | 32 | } |
|
| 33 | 33 | ||
| 34 | 34 | @default fn main() -> i32 { |
|
| 35 | - | if not testPtrSameAddress() { |
|
| 36 | - | return 1; |
|
| 37 | - | } |
|
| 38 | - | if not testPtrDifferentAddressSameValues() { |
|
| 39 | - | return 2; |
|
| 40 | - | } |
|
| 41 | - | if not testPtrDifferentAddressDifferentValues() { |
|
| 42 | - | return 3; |
|
| 43 | - | } |
|
| 35 | + | assert testPtrSameAddress(); |
|
| 36 | + | assert testPtrDifferentAddressSameValues(); |
|
| 37 | + | assert testPtrDifferentAddressDifferentValues(); |
|
| 44 | 38 | return 0; |
|
| 45 | 39 | } |
lib/std/arch/rv64/tests/ptr.opaque.rad
+4 -12
| 46 | 46 | } |
|
| 47 | 47 | return false; |
|
| 48 | 48 | } |
|
| 49 | 49 | ||
| 50 | 50 | @default fn main() -> u32 { |
|
| 51 | - | if not testOpaqueCasting() { |
|
| 52 | - | return 1; |
|
| 53 | - | } |
|
| 54 | - | if not testOpaqueParams() { |
|
| 55 | - | return 2; |
|
| 56 | - | } |
|
| 57 | - | if not testOpaqueReturn() { |
|
| 58 | - | return 3; |
|
| 59 | - | } |
|
| 60 | - | if not testNullableOpaque() { |
|
| 61 | - | return 4; |
|
| 62 | - | } |
|
| 51 | + | assert testOpaqueCasting(); |
|
| 52 | + | assert testOpaqueParams(); |
|
| 53 | + | assert testOpaqueReturn(); |
|
| 54 | + | assert testNullableOpaque(); |
|
| 63 | 55 | return 0; |
|
| 64 | 56 | } |
lib/std/arch/rv64/tests/record.alignment.rad
+2 -6
| 4 | 4 | a: i32, |
|
| 5 | 5 | b: i32, |
|
| 6 | 6 | } |
|
| 7 | 7 | ||
| 8 | 8 | @default fn main() -> i32 { |
|
| 9 | - | if @alignOf(R) != 4 { |
|
| 10 | - | return 1; |
|
| 11 | - | } |
|
| 12 | - | if @sizeOf(R) != 8 { |
|
| 13 | - | return 2; |
|
| 14 | - | } |
|
| 9 | + | assert @alignOf(R) == 4; |
|
| 10 | + | assert @sizeOf(R) == 8; |
|
| 15 | 11 | return 0; |
|
| 16 | 12 | } |
lib/std/arch/rv64/tests/record.copy.rad
+26 -78
| 18 | 18 | let mut m: S = s; |
|
| 19 | 19 | m.x = 112; |
|
| 20 | 20 | m.y = 582; |
|
| 21 | 21 | m.z = 281; |
|
| 22 | 22 | ||
| 23 | - | if m.x != 112 { |
|
| 24 | - | return 1; |
|
| 25 | - | } |
|
| 26 | - | if m.y != 582 { |
|
| 27 | - | return 2; |
|
| 28 | - | } |
|
| 29 | - | if m.z != 281 { |
|
| 30 | - | return 3; |
|
| 31 | - | } |
|
| 23 | + | assert m.x == 112; |
|
| 24 | + | assert m.y == 582; |
|
| 25 | + | assert m.z == 281; |
|
| 32 | 26 | return 0; |
|
| 33 | 27 | } |
|
| 34 | 28 | ||
| 35 | 29 | fn func2(s: S) -> i32 { |
|
| 36 | 30 | let p: i32 = 0; |
| 43 | 37 | t.y = 52; |
|
| 44 | 38 | u.y = 54; |
|
| 45 | 39 | t.z = 21; |
|
| 46 | 40 | u.z = 25; |
|
| 47 | 41 | ||
| 48 | - | if t.x != 12 { |
|
| 49 | - | return 1; |
|
| 50 | - | } |
|
| 51 | - | if t.y != 52 { |
|
| 52 | - | return 2; |
|
| 53 | - | } |
|
| 54 | - | if t.z != 21 { |
|
| 55 | - | return 3; |
|
| 56 | - | } |
|
| 57 | - | if u.x != 13 { |
|
| 58 | - | return 4; |
|
| 59 | - | } |
|
| 60 | - | if u.y != 54 { |
|
| 61 | - | return 5; |
|
| 62 | - | } |
|
| 63 | - | if u.z != 25 { |
|
| 64 | - | return 6; |
|
| 65 | - | } |
|
| 42 | + | assert t.x == 12; |
|
| 43 | + | assert t.y == 52; |
|
| 44 | + | assert t.z == 21; |
|
| 45 | + | assert u.x == 13; |
|
| 46 | + | assert u.y == 54; |
|
| 47 | + | assert u.z == 25; |
|
| 66 | 48 | return 0; |
|
| 67 | 49 | } |
|
| 68 | 50 | ||
| 69 | 51 | fn func3(s: S) -> i32 { |
|
| 70 | 52 | let mut a: [S; 4] = [s; 4]; |
| 75 | 57 | t.z = 52; |
|
| 76 | 58 | ||
| 77 | 59 | a[1] = t; |
|
| 78 | 60 | a[3] = a[1]; |
|
| 79 | 61 | ||
| 80 | - | if a[0].x != 561 { |
|
| 81 | - | return 1; |
|
| 82 | - | } |
|
| 83 | - | if a[0].y != 938 { |
|
| 84 | - | return 2; |
|
| 85 | - | } |
|
| 86 | - | if a[0].z != 102 { |
|
| 87 | - | return 3; |
|
| 88 | - | } |
|
| 89 | - | if a[1].x != 12 { |
|
| 90 | - | return 4; |
|
| 91 | - | } |
|
| 92 | - | if a[1].y != 13 { |
|
| 93 | - | return 5; |
|
| 94 | - | } |
|
| 95 | - | if a[1].z != 52 { |
|
| 96 | - | return 6; |
|
| 97 | - | } |
|
| 98 | - | if a[2].x != 561 { |
|
| 99 | - | return 7; |
|
| 100 | - | } |
|
| 101 | - | if a[3].x != 12 { |
|
| 102 | - | return 8; |
|
| 103 | - | } |
|
| 62 | + | assert a[0].x == 561; |
|
| 63 | + | assert a[0].y == 938; |
|
| 64 | + | assert a[0].z == 102; |
|
| 65 | + | assert a[1].x == 12; |
|
| 66 | + | assert a[1].y == 13; |
|
| 67 | + | assert a[1].z == 52; |
|
| 68 | + | assert a[2].x == 561; |
|
| 69 | + | assert a[3].x == 12; |
|
| 104 | 70 | return 0; |
|
| 105 | 71 | } |
|
| 106 | 72 | ||
| 107 | 73 | fn func4(s: S) -> i32 { |
|
| 108 | 74 | let mut a: [S; 2] = undefined; |
|
| 109 | 75 | a[0] = s; |
|
| 110 | 76 | ||
| 111 | - | if a[0].x != 561 { |
|
| 112 | - | return 1; |
|
| 113 | - | } |
|
| 114 | - | if a[0].y != 938 { |
|
| 115 | - | return 2; |
|
| 116 | - | } |
|
| 117 | - | if a[0].z != 102 { |
|
| 118 | - | return 3; |
|
| 119 | - | } |
|
| 77 | + | assert a[0].x == 561; |
|
| 78 | + | assert a[0].y == 938; |
|
| 79 | + | assert a[0].z == 102; |
|
| 120 | 80 | return 0; |
|
| 121 | 81 | } |
|
| 122 | 82 | ||
| 123 | 83 | fn func5(s: S) -> i32 { |
|
| 124 | 84 | let mut a: [S; 2] = undefined; |
|
| 125 | 85 | let t: S = makeS(s.x, s.y, s.z); |
|
| 126 | 86 | a[0] = t; |
|
| 127 | 87 | ||
| 128 | - | if a[0].x != 561 { |
|
| 129 | - | return 1; |
|
| 130 | - | } |
|
| 131 | - | if a[0].y != 938 { |
|
| 132 | - | return 2; |
|
| 133 | - | } |
|
| 134 | - | if a[0].z != 102 { |
|
| 135 | - | return 3; |
|
| 136 | - | } |
|
| 88 | + | assert a[0].x == 561; |
|
| 89 | + | assert a[0].y == 938; |
|
| 90 | + | assert a[0].z == 102; |
|
| 137 | 91 | return 0; |
|
| 138 | 92 | } |
|
| 139 | 93 | ||
| 140 | 94 | @default fn main() -> i32 { |
|
| 141 | 95 | let s: S = S { x: 561, y: 938, z: 102 }; |
|
| 142 | 96 | ||
| 143 | 97 | let r1: i32 = func1(s); |
|
| 144 | 98 | if r1 != 0 { |
|
| 145 | 99 | return 10 + r1; |
|
| 146 | 100 | } |
|
| 147 | - | if s.x != 561 { |
|
| 148 | - | return 20; |
|
| 149 | - | } |
|
| 150 | - | if s.y != 938 { |
|
| 151 | - | return 21; |
|
| 152 | - | } |
|
| 153 | - | if s.z != 102 { |
|
| 154 | - | return 22; |
|
| 155 | - | } |
|
| 101 | + | assert s.x == 561; |
|
| 102 | + | assert s.y == 938; |
|
| 103 | + | assert s.z == 102; |
|
| 156 | 104 | ||
| 157 | 105 | let r2: i32 = func2(s); |
|
| 158 | 106 | if r2 != 0 { |
|
| 159 | 107 | return 30 + r2; |
|
| 160 | 108 | } |
lib/std/arch/rv64/tests/record.nested.calls.2.rad
+1 -3
| 22 | 22 | scale(p, 2), // (6, 8) |
|
| 23 | 23 | scale(q, 2) // (10, 12) |
|
| 24 | 24 | ); // (16, 20) |
|
| 25 | 25 | ||
| 26 | 26 | // p.x + p.y = 16 + 20 = 36 |
|
| 27 | - | if p.x + p.y != 36 { |
|
| 28 | - | return 1; |
|
| 29 | - | } |
|
| 27 | + | assert p.x + p.y == 36; |
|
| 30 | 28 | return 0; |
|
| 31 | 29 | } |
lib/std/arch/rv64/tests/record.nested.calls.3.rad
+1 -3
| 31 | 31 | return Point { x: id(2), y: id(3) }; |
|
| 32 | 32 | } |
|
| 33 | 33 | ||
| 34 | 34 | @default fn main() -> i32 { |
|
| 35 | 35 | let result: i32 = compute(point()).y - compute(point()).x; |
|
| 36 | - | if result != 2 { |
|
| 37 | - | return 1; |
|
| 38 | - | } |
|
| 36 | + | assert result == 2; |
|
| 39 | 37 | return 0; |
|
| 40 | 38 | } |
lib/std/arch/rv64/tests/ref.if.bug.rad
+2 -6
| 15 | 15 | } |
|
| 16 | 16 | return val; |
|
| 17 | 17 | } |
|
| 18 | 18 | ||
| 19 | 19 | @default fn main() -> i32 { |
|
| 20 | - | if testIfBranch(false) != 42 { |
|
| 21 | - | return 1; |
|
| 22 | - | } |
|
| 23 | - | if testIfBranch(true) != 99 { |
|
| 24 | - | return 2; |
|
| 25 | - | } |
|
| 20 | + | assert testIfBranch(false) == 42; |
|
| 21 | + | assert testIfBranch(true) == 99; |
|
| 26 | 22 | return 0; |
|
| 27 | 23 | } |
lib/std/arch/rv64/tests/ref.immut.loop.bug.rad
+2 -6
| 19 | 19 | } |
|
| 20 | 20 | return val; |
|
| 21 | 21 | } |
|
| 22 | 22 | ||
| 23 | 23 | @default fn main() -> i32 { |
|
| 24 | - | if testZeroIter(0) != 42 { |
|
| 25 | - | return 1; |
|
| 26 | - | } |
|
| 27 | - | if testZeroIter(3) != 42 { |
|
| 28 | - | return 2; |
|
| 29 | - | } |
|
| 24 | + | assert testZeroIter(0) == 42; |
|
| 25 | + | assert testZeroIter(3) == 42; |
|
| 30 | 26 | return 0; |
|
| 31 | 27 | } |
lib/std/arch/rv64/tests/regalloc.callee.save.rad
+1 -3
| 39 | 39 | let v12: i32 = consume(v0); |
|
| 40 | 40 | ||
| 41 | 41 | let total: i32 = v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 + v9 + v10 + v11 + v12; |
|
| 42 | 42 | // v1..v10 = 2+3+...+11 = 65, v11 = 12, v12 = consume(1) = 2 |
|
| 43 | 43 | // total = 65 + 12 + 2 = 79 |
|
| 44 | - | if total != 79 { |
|
| 45 | - | return 1; |
|
| 46 | - | } |
|
| 44 | + | assert total == 79; |
|
| 47 | 45 | return 0; |
|
| 48 | 46 | } |
lib/std/arch/rv64/tests/regalloc.spill.reuse.rad
+1 -3
| 6 | 6 | let saved: u32 = old + 1; |
|
| 7 | 7 | ||
| 8 | 8 | let first: u32 = callPressure(1, 2, 3, 4, 5, 6, 7, 8); |
|
| 9 | 9 | let second: u32 = callPressure(8, 7, 6, 5, 4, 3, 2, 1); |
|
| 10 | 10 | ||
| 11 | - | if first == 0 or second == 0 { |
|
| 12 | - | return 99; |
|
| 13 | - | } |
|
| 11 | + | assert first != 0 and second != 0; |
|
| 14 | 12 | ||
| 15 | 13 | return saved; |
|
| 16 | 14 | } |
|
| 17 | 15 | ||
| 18 | 16 | @default fn main() -> i32 { |
lib/std/arch/rv64/tests/reserve.loop.rad
+1 -3
| 8 | 8 | total += p.a + p.b; |
|
| 9 | 9 | i += 1; |
|
| 10 | 10 | } |
|
| 11 | 11 | // Expected: sum(i) + sum(i+1) for i=0..9999 |
|
| 12 | 12 | // = 2 * 9999*10000/2 + 10000 = 99990000 + 10000 = 100000000 |
|
| 13 | - | if total != 100000000 { |
|
| 14 | - | return 1; |
|
| 15 | - | } |
|
| 13 | + | assert total == 100000000; |
|
| 16 | 14 | return 0; |
|
| 17 | 15 | } |
lib/std/arch/rv64/tests/slice.alloc.loop.rad
+2 -6
| 22 | 22 | ||
| 23 | 23 | @default fn main() -> i32 { |
|
| 24 | 24 | let mut buf: [u8; 64] = undefined; |
|
| 25 | 25 | ||
| 26 | 26 | let n = initSlice(&mut buf[..], 5); |
|
| 27 | - | if n != 5 { |
|
| 28 | - | return 1; |
|
| 29 | - | } |
|
| 27 | + | assert n == 5; |
|
| 30 | 28 | ||
| 31 | 29 | let n2 = initSlice(&mut buf[..], 0); |
|
| 32 | - | if n2 != 0 { |
|
| 33 | - | return 2; |
|
| 34 | - | } |
|
| 30 | + | assert n2 == 0; |
|
| 35 | 31 | ||
| 36 | 32 | return 0; |
|
| 37 | 33 | } |
lib/std/arch/rv64/tests/slice.of.rad
+4 -12
| 6 | 6 | ||
| 7 | 7 | @default fn main() -> i32 { |
|
| 8 | 8 | let mut arr: [i32; 4] = [10, 20, 30, 40]; |
|
| 9 | 9 | let s = makeSlice(&mut arr[0], 4); |
|
| 10 | 10 | ||
| 11 | - | if s.len != 4 { |
|
| 12 | - | return 1; |
|
| 13 | - | } |
|
| 14 | - | if s[0] != 10 { |
|
| 15 | - | return 2; |
|
| 16 | - | } |
|
| 17 | - | if s[3] != 40 { |
|
| 18 | - | return 3; |
|
| 19 | - | } |
|
| 11 | + | assert s.len == 4; |
|
| 12 | + | assert s[0] == 10; |
|
| 13 | + | assert s[3] == 40; |
|
| 20 | 14 | ||
| 21 | 15 | // Test with count=0. |
|
| 22 | 16 | let empty = makeSlice(&mut arr[0], 0); |
|
| 23 | - | if empty.len != 0 { |
|
| 24 | - | return 4; |
|
| 25 | - | } |
|
| 17 | + | assert empty.len == 0; |
|
| 26 | 18 | return 0; |
|
| 27 | 19 | } |
lib/std/arch/rv64/tests/spill.blockarg.clobber.rad
+2 -6
| 118 | 118 | ||
| 119 | 119 | prepareSchedule(&mut s, &block[..]); |
|
| 120 | 120 | compress(&mut s, &k[..]); |
|
| 121 | 121 | ||
| 122 | 122 | // SHA-256("") = e3b0c442 98fc1c14 ... |
|
| 123 | - | if s.h[0] != 0xE3B0C442 { |
|
| 124 | - | return 1; |
|
| 125 | - | } |
|
| 126 | - | if s.h[1] != 0x98FC1C14 { |
|
| 127 | - | return 2; |
|
| 128 | - | } |
|
| 123 | + | assert s.h[0] == 0xE3B0C442; |
|
| 124 | + | assert s.h[1] == 0x98FC1C14; |
|
| 129 | 125 | return 0; |
|
| 130 | 126 | } |
lib/std/arch/rv64/tests/spill.loop.rad
+4 -12
| 47 | 47 | ||
| 48 | 48 | @default fn main() -> i32 { |
|
| 49 | 49 | // Two u32 fields (tag 2 = size=4, align=4). |
|
| 50 | 50 | let mut tags: [u8; 2] = [2, 2]; |
|
| 51 | 51 | let layout = computeRecordLayout(&tags[0..2]); |
|
| 52 | - | if layout.alignment != 4 { |
|
| 53 | - | return 1; |
|
| 54 | - | } |
|
| 55 | - | if layout.size != 8 { |
|
| 56 | - | return 2; |
|
| 57 | - | } |
|
| 52 | + | assert layout.alignment == 4; |
|
| 53 | + | assert layout.size == 8; |
|
| 58 | 54 | ||
| 59 | 55 | // Mixed: u8 then u32. |
|
| 60 | 56 | let mut tags2: [u8; 2] = [0, 2]; |
|
| 61 | 57 | let layout2 = computeRecordLayout(&tags2[0..2]); |
|
| 62 | - | if layout2.alignment != 4 { |
|
| 63 | - | return 3; |
|
| 64 | - | } |
|
| 65 | - | if layout2.size != 8 { |
|
| 66 | - | return 4; |
|
| 67 | - | } |
|
| 58 | + | assert layout2.alignment == 4; |
|
| 59 | + | assert layout2.size == 8; |
|
| 68 | 60 | return 0; |
|
| 69 | 61 | } |
lib/std/arch/rv64/tests/stack.local.corrupt.rad
+2 -6
| 5 | 5 | ||
| 6 | 6 | @default fn main() -> i32 { |
|
| 7 | 7 | let mut local: i32 = 42; |
|
| 8 | 8 | let result = identity(10); |
|
| 9 | 9 | // Check that local wasn't corrupted by the call |
|
| 10 | - | if local != 42 { |
|
| 11 | - | return 1; |
|
| 12 | - | } |
|
| 13 | - | if result != 10 { |
|
| 14 | - | return 2; |
|
| 15 | - | } |
|
| 10 | + | assert local == 42; |
|
| 11 | + | assert result == 10; |
|
| 16 | 12 | return 0; |
|
| 17 | 13 | } |
lib/std/arch/rv64/tests/static.array.mutate.rad
+1 -3
| 11 | 11 | let a: i32 = bump(0, 4); |
|
| 12 | 12 | let b: i32 = bump(1, 5); |
|
| 13 | 13 | let c: i32 = bump(2, 6); |
|
| 14 | 14 | ||
| 15 | 15 | // a=10, b=15, c=21 => total=46 |
|
| 16 | - | if a + b + c != 46 { |
|
| 17 | - | return 1; |
|
| 18 | - | } |
|
| 16 | + | assert a + b + c == 46; |
|
| 19 | 17 | return 0; |
|
| 20 | 18 | } |
lib/std/arch/rv64/tests/static.fn.array.rad
+3 -9
| 18 | 18 | static OPS: [fn(i32) -> i32; 3] = [double, negate, identity]; |
|
| 19 | 19 | ||
| 20 | 20 | @default fn main() -> i32 { |
|
| 21 | 21 | // double(5) == 10 |
|
| 22 | 22 | let r0 = OPS[0](5); |
|
| 23 | - | if r0 != 10 { |
|
| 24 | - | return 1; |
|
| 25 | - | } |
|
| 23 | + | assert r0 == 10; |
|
| 26 | 24 | // negate(5) == -5 |
|
| 27 | 25 | let r1 = OPS[1](5); |
|
| 28 | - | if r1 != 0 - 5 { |
|
| 29 | - | return 2; |
|
| 30 | - | } |
|
| 26 | + | assert r1 == 0 - 5; |
|
| 31 | 27 | // identity(5) == 5 |
|
| 32 | 28 | let r2 = OPS[2](5); |
|
| 33 | - | if r2 != 5 { |
|
| 34 | - | return 3; |
|
| 35 | - | } |
|
| 29 | + | assert r2 == 5; |
|
| 36 | 30 | return 0; |
|
| 37 | 31 | } |
lib/std/arch/rv64/tests/static.record.array.rad
+1 -3
| 18 | 18 | ||
| 19 | 19 | @default fn main() -> i32 { |
|
| 20 | 20 | let first: i32 = rebalance(); |
|
| 21 | 21 | let second: i32 = TABLE.values[1] + TABLE.values[2]; |
|
| 22 | 22 | ||
| 23 | - | if first + second != 26 { |
|
| 24 | - | return 1; |
|
| 25 | - | } |
|
| 23 | + | assert first + second == 26; |
|
| 26 | 24 | return 0; |
|
| 27 | 25 | } |
lib/std/arch/rv64/tests/static.slice.offset.rad
+2 -6
| 24 | 24 | TBL.len = 0; |
|
| 25 | 25 | ||
| 26 | 26 | TBL.entries[TBL.len] = Entry { a: 7, b: 9 }; |
|
| 27 | 27 | TBL.len += 1; |
|
| 28 | 28 | ||
| 29 | - | if STORAGE[0].a != 7 or STORAGE[0].b != 9 { |
|
| 30 | - | return 1; |
|
| 31 | - | } |
|
| 32 | - | if SCRATCH[0].a != 0 or SCRATCH[0].b != 0 { |
|
| 33 | - | return 2; |
|
| 34 | - | } |
|
| 29 | + | assert STORAGE[0].a == 7 and STORAGE[0].b == 9; |
|
| 30 | + | assert SCRATCH[0].a == 0 and SCRATCH[0].b == 0; |
|
| 35 | 31 | return 0; |
|
| 36 | 32 | } |
lib/std/arch/rv64/tests/switch.blockargs.clobber.rad
+5 -15
| 19 | 19 | @default fn main() -> i32 { |
|
| 20 | 20 | // Critical case: two payload values that differ. |
|
| 21 | 21 | // With the bug, the switch clobber makes this return true. |
|
| 22 | 22 | let a: Val = Val::data(42); |
|
| 23 | 23 | let b: Val = Val::data(99); |
|
| 24 | - | if a == b { |
|
| 25 | - | return 1; |
|
| 26 | - | } |
|
| 24 | + | assert a != b; |
|
| 27 | 25 | ||
| 28 | 26 | // Same payload - should be equal. |
|
| 29 | 27 | let c: Val = Val::data(42); |
|
| 30 | 28 | let d: Val = Val::data(42); |
|
| 31 | - | if c != d { |
|
| 32 | - | return 2; |
|
| 33 | - | } |
|
| 29 | + | assert c == d; |
|
| 34 | 30 | ||
| 35 | 31 | // Both void (none) - should be equal. |
|
| 36 | 32 | let e: Val = Val::none; |
|
| 37 | 33 | let f: Val = Val::none; |
|
| 38 | - | if e != f { |
|
| 39 | - | return 3; |
|
| 40 | - | } |
|
| 34 | + | assert e == f; |
|
| 41 | 35 | ||
| 42 | 36 | // Both void (empty) - should be equal. |
|
| 43 | 37 | let g: Val = Val::empty; |
|
| 44 | 38 | let h: Val = Val::empty; |
|
| 45 | - | if g != h { |
|
| 46 | - | return 4; |
|
| 47 | - | } |
|
| 39 | + | assert g == h; |
|
| 48 | 40 | ||
| 49 | 41 | // Different variants - should not be equal. |
|
| 50 | 42 | let i: Val = Val::none; |
|
| 51 | 43 | let j: Val = Val::data(42); |
|
| 52 | - | if i == j { |
|
| 53 | - | return 5; |
|
| 54 | - | } |
|
| 44 | + | assert i != j; |
|
| 55 | 45 | return 0; |
|
| 56 | 46 | } |
lib/std/arch/rv64/tests/trait.aggregate.ret.rad
+6 -18
| 47 | 47 | let c = Circle { cx: 10, cy: 20, radius: 5 }; |
|
| 48 | 48 | let g: *opaque Geometry = &c; |
|
| 49 | 49 | ||
| 50 | 50 | // Small struct return (Point, 8 bytes = pointer size). |
|
| 51 | 51 | let p = g.origin(); |
|
| 52 | - | if p.x != 10 { |
|
| 53 | - | return 1; |
|
| 54 | - | } |
|
| 55 | - | if p.y != 20 { |
|
| 56 | - | return 2; |
|
| 57 | - | } |
|
| 52 | + | assert p.x == 10; |
|
| 53 | + | assert p.y == 20; |
|
| 58 | 54 | ||
| 59 | 55 | // Larger struct return (Vec3, 12 bytes > pointer size). |
|
| 60 | 56 | let v = g.center(); |
|
| 61 | - | if v.x != 10 { |
|
| 62 | - | return 3; |
|
| 63 | - | } |
|
| 64 | - | if v.y != 20 { |
|
| 65 | - | return 4; |
|
| 66 | - | } |
|
| 67 | - | if v.z != 0 { |
|
| 68 | - | return 5; |
|
| 69 | - | } |
|
| 57 | + | assert v.x == 10; |
|
| 58 | + | assert v.y == 20; |
|
| 59 | + | assert v.z == 0; |
|
| 70 | 60 | ||
| 71 | 61 | // Optional return - Some case. |
|
| 72 | 62 | let m = g.maybe(); |
|
| 73 | 63 | if let val = m { |
|
| 74 | - | if val != 5 { |
|
| 75 | - | return 6; |
|
| 76 | - | } |
|
| 64 | + | assert val == 5; |
|
| 77 | 65 | } else { |
|
| 78 | 66 | return 7; |
|
| 79 | 67 | } |
|
| 80 | 68 | ||
| 81 | 69 | // Optional return - None case. |
lib/std/arch/rv64/tests/trait.array.optional.rad
+3 -9
| 55 | 55 | ||
| 56 | 56 | // Array of trait objects. |
|
| 57 | 57 | let transforms: [*opaque Transform; 3] = [t1, t2, t3]; |
|
| 58 | 58 | // Chain: (1 + 10) * 3 + 5 = 38 |
|
| 59 | 59 | let result = applyAll(&transforms[..], 1); |
|
| 60 | - | if result != 38 { |
|
| 61 | - | return 1; |
|
| 62 | - | } |
|
| 60 | + | assert result == 38; |
|
| 63 | 61 | ||
| 64 | 62 | // Optional trait object - Some case. |
|
| 65 | 63 | let opt: ?*opaque Transform = t1; |
|
| 66 | 64 | let r2 = applyMaybe(opt, 5); |
|
| 67 | - | if r2 != 15 { |
|
| 68 | - | return 2; |
|
| 69 | - | } |
|
| 65 | + | assert r2 == 15; |
|
| 70 | 66 | ||
| 71 | 67 | // Optional trait object - None case. |
|
| 72 | 68 | let none: ?*opaque Transform = nil; |
|
| 73 | 69 | let r3 = applyMaybe(none, 5); |
|
| 74 | - | if r3 != 5 { |
|
| 75 | - | return 3; |
|
| 76 | - | } |
|
| 70 | + | assert r3 == 5; |
|
| 77 | 71 | ||
| 78 | 72 | return 0; |
|
| 79 | 73 | } |
lib/std/arch/rv64/tests/trait.basic.rad
+2 -6
| 18 | 18 | let mut c = Counter { value: 10 }; |
|
| 19 | 19 | let a: *mut opaque Adder = &mut c; |
|
| 20 | 20 | ||
| 21 | 21 | let result = a.add(5); |
|
| 22 | 22 | // c.value should be 15 now. |
|
| 23 | - | if result != 15 { |
|
| 24 | - | return 1; |
|
| 25 | - | } |
|
| 23 | + | assert result == 15; |
|
| 26 | 24 | let result2 = a.add(3); |
|
| 27 | 25 | // c.value should be 18 now. |
|
| 28 | - | if result2 != 18 { |
|
| 29 | - | return 2; |
|
| 30 | - | } |
|
| 26 | + | assert result2 == 18; |
|
| 31 | 27 | return 0; |
|
| 32 | 28 | } |
lib/std/arch/rv64/tests/trait.control.flow.rad
+4 -12
| 32 | 32 | let mut i: i32 = 0; |
|
| 33 | 33 | while i < 5 { |
|
| 34 | 34 | s.step(); |
|
| 35 | 35 | i = i + 1; |
|
| 36 | 36 | } |
|
| 37 | - | if s.current() != 5 { |
|
| 38 | - | return 1; |
|
| 39 | - | } |
|
| 37 | + | assert s.current() == 5; |
|
| 40 | 38 | ||
| 41 | 39 | // Dispatch in a conditional. |
|
| 42 | 40 | if s.current() > 3 { |
|
| 43 | 41 | s.step(); |
|
| 44 | 42 | } |
|
| 45 | - | if s.current() != 6 { |
|
| 46 | - | return 2; |
|
| 47 | - | } |
|
| 43 | + | assert s.current() == 6; |
|
| 48 | 44 | ||
| 49 | 45 | // Dispatch result used as loop condition. |
|
| 50 | 46 | while s.current() < 10 { |
|
| 51 | 47 | s.step(); |
|
| 52 | 48 | } |
|
| 53 | - | if s.current() != 10 { |
|
| 54 | - | return 3; |
|
| 55 | - | } |
|
| 49 | + | assert s.current() == 10; |
|
| 56 | 50 | ||
| 57 | 51 | // Dispatch result used in conditional expression. |
|
| 58 | 52 | let v = s.current(); |
|
| 59 | - | if v != 10 { |
|
| 60 | - | return 4; |
|
| 61 | - | } |
|
| 53 | + | assert v == 10; |
|
| 62 | 54 | return 0; |
|
| 63 | 55 | } |
lib/std/arch/rv64/tests/trait.fn.param.rad
+4 -12
| 57 | 57 | let s = Square { side: 4 }; |
|
| 58 | 58 | ||
| 59 | 59 | // Pass immutable trait objects to function. |
|
| 60 | 60 | let cs: *opaque Shape = &c; |
|
| 61 | 61 | let ca = getArea(cs); |
|
| 62 | - | if ca != 75 { |
|
| 63 | - | return 1; |
|
| 64 | - | } |
|
| 62 | + | assert ca == 75; |
|
| 65 | 63 | ||
| 66 | 64 | let ss: *opaque Shape = &s; |
|
| 67 | 65 | let sa = getArea(ss); |
|
| 68 | - | if sa != 16 { |
|
| 69 | - | return 2; |
|
| 70 | - | } |
|
| 66 | + | assert sa == 16; |
|
| 71 | 67 | ||
| 72 | 68 | // Pass two different trait objects to same function. |
|
| 73 | 69 | let total = totalArea(cs, ss); |
|
| 74 | - | if total != 91 { |
|
| 75 | - | return 3; |
|
| 76 | - | } |
|
| 70 | + | assert total == 91; |
|
| 77 | 71 | ||
| 78 | 72 | // Pass mutable trait object to function. |
|
| 79 | 73 | let mut c2 = Circle { radius: 3 }; |
|
| 80 | 74 | let sc: *mut opaque Scalable = &mut c2; |
|
| 81 | 75 | doubleSize(sc); |
|
| 82 | - | if c2.radius != 6 { |
|
| 83 | - | return 4; |
|
| 84 | - | } |
|
| 76 | + | assert c2.radius == 6; |
|
| 85 | 77 | return 0; |
|
| 86 | 78 | } |
lib/std/arch/rv64/tests/trait.multiple.methods.rad
+5 -15
| 32 | 32 | @default fn main() -> i32 { |
|
| 33 | 33 | let mut acc = Accumulator { total: 0 }; |
|
| 34 | 34 | let c: *mut opaque Collector = &mut acc; |
|
| 35 | 35 | ||
| 36 | 36 | // Initially empty. |
|
| 37 | - | if not c.isEmpty() { |
|
| 38 | - | return 1; |
|
| 39 | - | } |
|
| 37 | + | assert c.isEmpty(); |
|
| 40 | 38 | ||
| 41 | 39 | // Add returns running total. |
|
| 42 | 40 | let v1 = c.add(10); |
|
| 43 | - | if v1 != 10 { |
|
| 44 | - | return 2; |
|
| 45 | - | } |
|
| 41 | + | assert v1 == 10; |
|
| 46 | 42 | ||
| 47 | 43 | let v2 = c.add(20); |
|
| 48 | - | if v2 != 30 { |
|
| 49 | - | return 3; |
|
| 50 | - | } |
|
| 44 | + | assert v2 == 30; |
|
| 51 | 45 | ||
| 52 | 46 | // No longer empty. |
|
| 53 | 47 | if c.isEmpty() { |
|
| 54 | 48 | return 4; |
|
| 55 | 49 | } |
|
| 56 | 50 | ||
| 57 | 51 | // Void return: clear. |
|
| 58 | 52 | c.clear(); |
|
| 59 | - | if acc.total != 0 { |
|
| 60 | - | return 5; |
|
| 61 | - | } |
|
| 62 | - | if not c.isEmpty() { |
|
| 63 | - | return 6; |
|
| 64 | - | } |
|
| 53 | + | assert acc.total == 0; |
|
| 54 | + | assert c.isEmpty(); |
|
| 65 | 55 | return 0; |
|
| 66 | 56 | } |
lib/std/arch/rv64/tests/trait.multiple.traits.rad
+4 -12
| 38 | 38 | let mut c = Counter { value: 10 }; |
|
| 39 | 39 | ||
| 40 | 40 | // Dispatch through Incrementable. |
|
| 41 | 41 | let i: *mut opaque Incrementable = &mut c; |
|
| 42 | 42 | let v1 = i.inc(); |
|
| 43 | - | if v1 != 11 { |
|
| 44 | - | return 1; |
|
| 45 | - | } |
|
| 43 | + | assert v1 == 11; |
|
| 46 | 44 | ||
| 47 | 45 | // Dispatch through Resettable. |
|
| 48 | 46 | let r: *mut opaque Resettable = &mut c; |
|
| 49 | 47 | if r.isZero() { |
|
| 50 | 48 | return 2; |
|
| 51 | 49 | } |
|
| 52 | 50 | r.reset(); |
|
| 53 | - | if not r.isZero() { |
|
| 54 | - | return 3; |
|
| 55 | - | } |
|
| 56 | - | if c.value != 0 { |
|
| 57 | - | return 4; |
|
| 58 | - | } |
|
| 51 | + | assert r.isZero(); |
|
| 52 | + | assert c.value == 0; |
|
| 59 | 53 | ||
| 60 | 54 | // Increment again after reset. |
|
| 61 | 55 | let v2 = i.inc(); |
|
| 62 | - | if v2 != 1 { |
|
| 63 | - | return 5; |
|
| 64 | - | } |
|
| 56 | + | assert v2 == 1; |
|
| 65 | 57 | return 0; |
|
| 66 | 58 | } |
lib/std/arch/rv64/tests/trait.multiple.types.rad
+3 -9
| 42 | 42 | let c = Cat { lives: 9 }; |
|
| 43 | 43 | ||
| 44 | 44 | // Immutable trait object from Dog. |
|
| 45 | 45 | let sd: *opaque Speaker = &d; |
|
| 46 | 46 | let v1 = sd.speak(); |
|
| 47 | - | if v1 != 5 { |
|
| 48 | - | return 1; |
|
| 49 | - | } |
|
| 47 | + | assert v1 == 5; |
|
| 50 | 48 | if sd.isOld() { |
|
| 51 | 49 | return 2; |
|
| 52 | 50 | } |
|
| 53 | 51 | ||
| 54 | 52 | // Immutable trait object from Cat. |
|
| 55 | 53 | let sc: *opaque Speaker = &c; |
|
| 56 | 54 | let v2 = sc.speak(); |
|
| 57 | - | if v2 != 90 { |
|
| 58 | - | return 3; |
|
| 59 | - | } |
|
| 55 | + | assert v2 == 90; |
|
| 60 | 56 | if sc.isOld() { |
|
| 61 | 57 | return 4; |
|
| 62 | 58 | } |
|
| 63 | 59 | ||
| 64 | 60 | // Old dog. |
|
| 65 | 61 | let oldDog = Dog { age: 15 }; |
|
| 66 | 62 | let so: *opaque Speaker = &oldDog; |
|
| 67 | - | if not so.isOld() { |
|
| 68 | - | return 5; |
|
| 69 | - | } |
|
| 63 | + | assert so.isOld(); |
|
| 70 | 64 | return 0; |
|
| 71 | 65 | } |
lib/std/arch/rv64/tests/trait.supertrait.rad
+7 -21
| 80 | 80 | // Test 1: Use as ReadWriter trait object. |
|
| 81 | 81 | let rw: *mut opaque ReadWriter = &mut sock; |
|
| 82 | 82 | ||
| 83 | 83 | // Test 2: Write through the ReadWriter (dispatches via Writer supertrait). |
|
| 84 | 84 | let wn = rw.write("abc"); |
|
| 85 | - | if wn != 3 { |
|
| 86 | - | return 1; |
|
| 87 | - | } |
|
| 88 | - | if sock.wpos != 3 { |
|
| 89 | - | return 2; |
|
| 90 | - | } |
|
| 85 | + | assert wn == 3; |
|
| 86 | + | assert sock.wpos == 3; |
|
| 91 | 87 | ||
| 92 | 88 | // Test 3: Read through the ReadWriter (dispatches via Reader supertrait). |
|
| 93 | 89 | let mut rbuf: [u8; 8] = undefined; |
|
| 94 | 90 | let rn = rw.read(&mut rbuf[0..8]); |
|
| 95 | - | if rn != 5 { |
|
| 96 | - | return 3; |
|
| 97 | - | } |
|
| 98 | - | if rbuf[0] != 'h' as u8 { |
|
| 99 | - | return 4; |
|
| 100 | - | } |
|
| 101 | - | if rbuf[4] != 'o' as u8 { |
|
| 102 | - | return 5; |
|
| 103 | - | } |
|
| 91 | + | assert rn == 5; |
|
| 92 | + | assert rbuf[0] == 'h' as u8; |
|
| 93 | + | assert rbuf[4] == 'o' as u8; |
|
| 104 | 94 | ||
| 105 | 95 | // Test 4: Call ReadWriter's own method. |
|
| 106 | 96 | let flushed = rw.flush(); |
|
| 107 | - | if flushed != 3 { |
|
| 108 | - | return 6; |
|
| 109 | - | } |
|
| 110 | - | if sock.wpos != 0 { |
|
| 111 | - | return 7; |
|
| 112 | - | } |
|
| 97 | + | assert flushed == 3; |
|
| 98 | + | assert sock.wpos == 0; |
|
| 113 | 99 | return 0; |
|
| 114 | 100 | } |
lib/std/arch/rv64/tests/trait.throws.rad
+3 -9
| 31 | 31 | ||
| 32 | 32 | // Success path. |
|
| 33 | 33 | let r1 = try p.parse(5) catch { |
|
| 34 | 34 | return 1; |
|
| 35 | 35 | }; |
|
| 36 | - | if r1 != 10 { |
|
| 37 | - | return 2; |
|
| 38 | - | } |
|
| 36 | + | assert r1 == 10; |
|
| 39 | 37 | ||
| 40 | 38 | // Error path: negative input. |
|
| 41 | 39 | let mut caught = false; |
|
| 42 | 40 | let r2 = try p.parse(-1) catch { |
|
| 43 | 41 | caught = true; |
|
| 44 | 42 | 0 |
|
| 45 | 43 | }; |
|
| 46 | - | if not caught { |
|
| 47 | - | return 3; |
|
| 48 | - | } |
|
| 44 | + | assert caught; |
|
| 49 | 45 | ||
| 50 | 46 | // Error path: overflow. |
|
| 51 | 47 | caught = false; |
|
| 52 | 48 | let r3 = try p.parse(200) catch { |
|
| 53 | 49 | caught = true; |
|
| 54 | 50 | 0 |
|
| 55 | 51 | }; |
|
| 56 | - | if not caught { |
|
| 57 | - | return 4; |
|
| 58 | - | } |
|
| 52 | + | assert caught; |
|
| 59 | 53 | ||
| 60 | 54 | return 0; |
|
| 61 | 55 | } |
lib/std/arch/rv64/tests/trait.writer.rad
+13 -39
| 60 | 60 | @default fn main() -> i32 { |
|
| 61 | 61 | // Direct BufferWriter usage through trait. |
|
| 62 | 62 | let mut buf = BufferWriter { buf: undefined, pos: 0 }; |
|
| 63 | 63 | let w: *mut opaque Writer = &mut buf; |
|
| 64 | 64 | emit(w, "hello"); |
|
| 65 | - | if w.total() != 5 { |
|
| 66 | - | return 1; |
|
| 67 | - | } |
|
| 65 | + | assert w.total() == 5; |
|
| 68 | 66 | emit(w, " world"); |
|
| 69 | - | if w.total() != 11 { |
|
| 70 | - | return 2; |
|
| 71 | - | } |
|
| 67 | + | assert w.total() == 11; |
|
| 72 | 68 | ||
| 73 | 69 | // Verify buffer contents. |
|
| 74 | - | if buf.buf[0] != 'h' as u8 { |
|
| 75 | - | return 3; |
|
| 76 | - | } |
|
| 77 | - | if buf.buf[4] != 'o' as u8 { |
|
| 78 | - | return 4; |
|
| 79 | - | } |
|
| 80 | - | if buf.buf[5] != ' ' as u8 { |
|
| 81 | - | return 5; |
|
| 82 | - | } |
|
| 83 | - | if buf.buf[10] != 'd' as u8 { |
|
| 84 | - | return 6; |
|
| 85 | - | } |
|
| 70 | + | assert buf.buf[0] == 'h' as u8; |
|
| 71 | + | assert buf.buf[4] == 'o' as u8; |
|
| 72 | + | assert buf.buf[5] == ' ' as u8; |
|
| 73 | + | assert buf.buf[10] == 'd' as u8; |
|
| 86 | 74 | ||
| 87 | 75 | // Counting writer wrapping a buffer writer. |
|
| 88 | 76 | let mut buf2 = BufferWriter { buf: undefined, pos: 0 }; |
|
| 89 | 77 | let bw2: *mut opaque Writer = &mut buf2; |
|
| 90 | 78 | let mut cw = CountingWriter { inner: bw2, count: 0 }; |
|
| 91 | 79 | let w2: *mut opaque Writer = &mut cw; |
|
| 92 | 80 | ||
| 93 | 81 | emit(w2, "abc"); |
|
| 94 | - | if cw.count != 3 { |
|
| 95 | - | return 7; |
|
| 96 | - | } |
|
| 82 | + | assert cw.count == 3; |
|
| 97 | 83 | // Underlying buffer also received the bytes. |
|
| 98 | - | if buf2.pos != 3 { |
|
| 99 | - | return 8; |
|
| 100 | - | } |
|
| 84 | + | assert buf2.pos == 3; |
|
| 101 | 85 | ||
| 102 | 86 | emit(w2, "defgh"); |
|
| 103 | - | if cw.count != 8 { |
|
| 104 | - | return 9; |
|
| 105 | - | } |
|
| 106 | - | if buf2.pos != 8 { |
|
| 107 | - | return 10; |
|
| 108 | - | } |
|
| 87 | + | assert cw.count == 8; |
|
| 88 | + | assert buf2.pos == 8; |
|
| 109 | 89 | ||
| 110 | 90 | // Check buf2 contents were forwarded correctly. |
|
| 111 | - | if buf2.buf[0] != 'a' as u8 { |
|
| 112 | - | return 11; |
|
| 113 | - | } |
|
| 114 | - | if buf2.buf[3] != 'd' as u8 { |
|
| 115 | - | return 12; |
|
| 116 | - | } |
|
| 117 | - | if buf2.buf[7] != 'h' as u8 { |
|
| 118 | - | return 13; |
|
| 119 | - | } |
|
| 91 | + | assert buf2.buf[0] == 'a' as u8; |
|
| 92 | + | assert buf2.buf[3] == 'd' as u8; |
|
| 93 | + | assert buf2.buf[7] == 'h' as u8; |
|
| 120 | 94 | return 0; |
|
| 121 | 95 | } |
lib/std/arch/rv64/tests/type.unify.rad
+8 -8
| 79 | 79 | fn testSizePromotion() -> bool { |
|
| 80 | 80 | let small: i8 = 5; |
|
| 81 | 81 | let large: i32 = 100; |
|
| 82 | 82 | let result: i32 = small as i32 + large; |
|
| 83 | 83 | ||
| 84 | - | let small_u: u8 = 10; |
|
| 85 | - | let large_u: u32 = 200; |
|
| 86 | - | let result2: u32 = small_u as u32 + large_u; |
|
| 84 | + | let smallU: u8 = 10; |
|
| 85 | + | let largeU: u32 = 200; |
|
| 86 | + | let result2: u32 = smallU as u32 + largeU; |
|
| 87 | 87 | ||
| 88 | 88 | return true; |
|
| 89 | 89 | } |
|
| 90 | 90 | ||
| 91 | 91 | /// Verifies basic optional assignments between values of the same optional type. |
| 100 | 100 | ||
| 101 | 101 | /// Verifies coercion from pointer values to optional pointer values. |
|
| 102 | 102 | fn testPointerToOptional() -> bool { |
|
| 103 | 103 | let value: i32 = 42; |
|
| 104 | 104 | let ptr: *i32 = &value; |
|
| 105 | - | let opt_ptr: ?*i32 = ptr; |
|
| 105 | + | let optPtr: ?*i32 = ptr; |
|
| 106 | 106 | ||
| 107 | 107 | return true; |
|
| 108 | 108 | } |
|
| 109 | 109 | ||
| 110 | 110 | /// Verifies creation of slices for different, but internally consistent, element types. |
|
| 111 | 111 | fn testSliceElementUnification() -> bool { |
|
| 112 | - | let arr_small: [i8; 3] = [1, 2, 3]; |
|
| 113 | - | let slice_small: *[i8] = &arr_small[..]; |
|
| 112 | + | let arrSmall: [i8; 3] = [1, 2, 3]; |
|
| 113 | + | let sliceSmall: *[i8] = &arrSmall[..]; |
|
| 114 | 114 | ||
| 115 | - | let arr_large: [i32; 3] = [10, 20, 30]; |
|
| 116 | - | let slice_large: *[i32] = &arr_large[..]; |
|
| 115 | + | let arrLarge: [i32; 3] = [10, 20, 30]; |
|
| 116 | + | let sliceLarge: *[i32] = &arrLarge[..]; |
|
| 117 | 117 | ||
| 118 | 118 | return true; |
|
| 119 | 119 | } |
|
| 120 | 120 | ||
| 121 | 121 | /// Verifies optional assignments involving `nil` and concrete values. |
lib/std/arch/rv64/tests/undefined.rad
+7 -21
| 8 | 8 | ary[1] = 2; |
|
| 9 | 9 | ary[2] = 3; |
|
| 10 | 10 | ary[3] = 4; |
|
| 11 | 11 | ary[4] = 5; |
|
| 12 | 12 | ||
| 13 | - | if x != 8 { |
|
| 14 | - | return 1; |
|
| 15 | - | } |
|
| 16 | - | if y != 9 { |
|
| 17 | - | return 2; |
|
| 18 | - | } |
|
| 19 | - | if ary[0] != 1 { |
|
| 20 | - | return 3; |
|
| 21 | - | } |
|
| 22 | - | if ary[1] != 2 { |
|
| 23 | - | return 4; |
|
| 24 | - | } |
|
| 25 | - | if ary[2] != 3 { |
|
| 26 | - | return 5; |
|
| 27 | - | } |
|
| 28 | - | if ary[3] != 4 { |
|
| 29 | - | return 6; |
|
| 30 | - | } |
|
| 31 | - | if ary[4] != 5 { |
|
| 32 | - | return 7; |
|
| 33 | - | } |
|
| 13 | + | assert x == 8; |
|
| 14 | + | assert y == 9; |
|
| 15 | + | assert ary[0] == 1; |
|
| 16 | + | assert ary[1] == 2; |
|
| 17 | + | assert ary[2] == 3; |
|
| 18 | + | assert ary[3] == 4; |
|
| 19 | + | assert ary[4] == 5; |
|
| 34 | 20 | return 0; |
|
| 35 | 21 | } |
lib/std/arch/rv64/tests/union-tag.rad
+7 -21
| 29 | 29 | return *p; |
|
| 30 | 30 | } |
|
| 31 | 31 | ||
| 32 | 32 | @default fn main() -> i32 { |
|
| 33 | 33 | let v0 = BigUnion::V0; |
|
| 34 | - | if tag(&v0) != 0 { |
|
| 35 | - | return 1; |
|
| 36 | - | } |
|
| 34 | + | assert tag(&v0) == 0; |
|
| 37 | 35 | let v7 = BigUnion::V7; |
|
| 38 | - | if tag(&v7) != 7 { |
|
| 39 | - | return 2; |
|
| 40 | - | } |
|
| 36 | + | assert tag(&v7) == 7; |
|
| 41 | 37 | let v13 = BigUnion::V13; |
|
| 42 | - | if tag(&v13) != 13 { |
|
| 43 | - | return 3; |
|
| 44 | - | } |
|
| 38 | + | assert tag(&v13) == 13; |
|
| 45 | 39 | let v14 = BigUnion::V14 { a: 1, b: 2 }; |
|
| 46 | - | if tag(&v14) != 14 { |
|
| 47 | - | return 4; |
|
| 48 | - | } |
|
| 40 | + | assert tag(&v14) == 14; |
|
| 49 | 41 | let v15 = BigUnion::V15 { x: 3, y: true }; |
|
| 50 | - | if tag(&v15) != 15 { |
|
| 51 | - | return 5; |
|
| 52 | - | } |
|
| 42 | + | assert tag(&v15) == 15; |
|
| 53 | 43 | let v16 = BigUnion::V16 { p: 4, q: false }; |
|
| 54 | - | if tag(&v16) != 16 { |
|
| 55 | - | return 6; |
|
| 56 | - | } |
|
| 44 | + | assert tag(&v16) == 16; |
|
| 57 | 45 | let v20 = BigUnion::V20; |
|
| 58 | - | if tag(&v20) != 20 { |
|
| 59 | - | return 7; |
|
| 60 | - | } |
|
| 46 | + | assert tag(&v20) == 20; |
|
| 61 | 47 | return 0; |
|
| 62 | 48 | } |
lib/std/arch/rv64/tests/union.discriminant.cast.rad
+4 -12
| 10 | 10 | @default fn main() -> i32 { |
|
| 11 | 11 | let a: i32 = U::A as i32; |
|
| 12 | 12 | let b: i32 = U::B as i32; |
|
| 13 | 13 | let c: i32 = U::C as i32; |
|
| 14 | 14 | ||
| 15 | - | if a != 7 { |
|
| 16 | - | return 1; |
|
| 17 | - | } |
|
| 18 | - | if b != 42 { |
|
| 19 | - | return 2; |
|
| 20 | - | } |
|
| 21 | - | if c != 255 { |
|
| 22 | - | return 3; |
|
| 23 | - | } |
|
| 24 | - | if (U::A as i32) + (U::B as i32) != 49 { |
|
| 25 | - | return 4; |
|
| 26 | - | } |
|
| 15 | + | assert a == 7; |
|
| 16 | + | assert b == 42; |
|
| 17 | + | assert c == 255; |
|
| 18 | + | assert (U::A as i32) + (U::B as i32) == 49; |
|
| 27 | 19 | return 0; |
|
| 28 | 20 | } |
lib/std/arch/rv64/tests/union.edge.case.3.rad
+1 -3
| 22 | 22 | @default fn main() -> u32 { |
|
| 23 | 23 | let mut parser = Parser { root: undefined }; |
|
| 24 | 24 | ||
| 25 | 25 | match *nodeBool(&mut parser, true) { |
|
| 26 | 26 | case Node::Bool(v) => { |
|
| 27 | - | if v != true { |
|
| 28 | - | return 1; |
|
| 29 | - | } |
|
| 27 | + | assert v == true; |
|
| 30 | 28 | return 0; |
|
| 31 | 29 | } |
|
| 32 | 30 | else => { |
|
| 33 | 31 | return 2; |
|
| 34 | 32 | } |
lib/std/arch/rv64/tests/union.mixed.assign.rad
+3 -9
| 30 | 30 | let mut holder = Holder { value: Mixed::Final }; |
|
| 31 | 31 | ||
| 32 | 32 | storePayload(&mut holder, 42); |
|
| 33 | 33 | let case Mixed::Payload(v) = holder.value |
|
| 34 | 34 | else return 1; |
|
| 35 | - | if v != 42 { |
|
| 36 | - | return 2; |
|
| 37 | - | } |
|
| 35 | + | assert v == 42; |
|
| 38 | 36 | ||
| 39 | - | if checkIfLet(Mixed::Standalone) != 0 { |
|
| 40 | - | return 3; |
|
| 41 | - | } |
|
| 37 | + | assert checkIfLet(Mixed::Standalone) == 0; |
|
| 42 | 38 | ||
| 43 | 39 | storeFinal(&mut holder); |
|
| 44 | - | if checkIfLet(holder.value) != 0 { |
|
| 45 | - | return 4; |
|
| 46 | - | } |
|
| 40 | + | assert checkIfLet(holder.value) == 0; |
|
| 47 | 41 | ||
| 48 | 42 | if let case Mixed::Payload(_) = Mixed::Standalone { |
|
| 49 | 43 | return 5; |
|
| 50 | 44 | } |
|
| 51 | 45 |
lib/std/arch/rv64/tests/union.payload.mutref.rad
+6 -18
| 38 | 38 | padding2: 0, |
|
| 39 | 39 | state: Sealed::No { items: U32List { data: &mut buf[0..8], len: 0 } }, |
|
| 40 | 40 | }; |
|
| 41 | 41 | ||
| 42 | 42 | // Add first item. |
|
| 43 | - | if not addItemViaMatchRef(&mut blk, 10) { |
|
| 44 | - | return 1; |
|
| 45 | - | } |
|
| 43 | + | assert addItemViaMatchRef(&mut blk, 10); |
|
| 46 | 44 | ||
| 47 | 45 | // Verify length was updated. |
|
| 48 | 46 | let case Sealed::No { items } = blk.state else { |
|
| 49 | 47 | return 2; |
|
| 50 | 48 | }; |
|
| 51 | - | if items.len != 1 { |
|
| 52 | - | return 3; |
|
| 53 | - | } |
|
| 49 | + | assert items.len == 1; |
|
| 54 | 50 | ||
| 55 | 51 | // Add second item. |
|
| 56 | - | if not addItemViaMatchRef(&mut blk, 20) { |
|
| 57 | - | return 4; |
|
| 58 | - | } |
|
| 52 | + | assert addItemViaMatchRef(&mut blk, 20); |
|
| 59 | 53 | ||
| 60 | 54 | // Verify length is 2. |
|
| 61 | 55 | let case Sealed::No { items: items2 } = blk.state else { |
|
| 62 | 56 | return 5; |
|
| 63 | 57 | }; |
|
| 64 | - | if items2.len != 2 { |
|
| 65 | - | return 6; |
|
| 66 | - | } |
|
| 58 | + | assert items2.len == 2; |
|
| 67 | 59 | ||
| 68 | 60 | // Verify values. |
|
| 69 | - | if items2.data[0] != 10 { |
|
| 70 | - | return 7; |
|
| 71 | - | } |
|
| 72 | - | if items2.data[1] != 20 { |
|
| 73 | - | return 8; |
|
| 74 | - | } |
|
| 61 | + | assert items2.data[0] == 10; |
|
| 62 | + | assert items2.data[1] == 20; |
|
| 75 | 63 | return 0; |
|
| 76 | 64 | } |
lib/std/arch/rv64/tests/union.payload.rad
+1 -3
| 12 | 12 | else => { return 1; } |
|
| 13 | 13 | } |
|
| 14 | 14 | // Test match `Some`. |
|
| 15 | 15 | match some { |
|
| 16 | 16 | case Option::Some(x) => { |
|
| 17 | - | if x != 42 { |
|
| 18 | - | return 2; |
|
| 19 | - | } |
|
| 17 | + | assert x == 42; |
|
| 20 | 18 | } |
|
| 21 | 19 | else => { return 3; } |
|
| 22 | 20 | } |
|
| 23 | 21 | // Test `None` doesn't match `Some`. |
|
| 24 | 22 | match none { |
lib/std/arch/rv64/tests/union.record.forward.rad
+1 -3
| 67 | 67 | return result; |
|
| 68 | 68 | } |
|
| 69 | 69 | ||
| 70 | 70 | @default fn main() -> i32 { |
|
| 71 | 71 | let value = blowUp(); |
|
| 72 | - | if value != 29 { |
|
| 73 | - | return 1; |
|
| 74 | - | } |
|
| 72 | + | assert value == 29; |
|
| 75 | 73 | return 0; |
|
| 76 | 74 | } |
lib/std/arch/rv64/tests/union.void.match.rad
+3 -9
| 12 | 12 | case Color::Blue => return 30, |
|
| 13 | 13 | } |
|
| 14 | 14 | } |
|
| 15 | 15 | ||
| 16 | 16 | @default fn main() -> i32 { |
|
| 17 | - | if getColorValue(Color::Red) != 10 { |
|
| 18 | - | return 1; |
|
| 19 | - | } |
|
| 20 | - | if getColorValue(Color::Green) != 20 { |
|
| 21 | - | return 2; |
|
| 22 | - | } |
|
| 23 | - | if getColorValue(Color::Blue) != 30 { |
|
| 24 | - | return 3; |
|
| 25 | - | } |
|
| 17 | + | assert getColorValue(Color::Red) == 10; |
|
| 18 | + | assert getColorValue(Color::Green) == 20; |
|
| 19 | + | assert getColorValue(Color::Blue) == 30; |
|
| 26 | 20 | return 0; |
|
| 27 | 21 | } |