| <!DOCTYPE html> |
| <html> |
| <meta charset=utf-8> |
| <meta name="timeout" content="long"> |
| <title>Test loops.</title> |
| <script src="js/test-harness.js"></script> |
| <script src="../js/webgpu-functions.js"></script> |
| <script src="../../resources/testharness.js"></script> |
| <script src="../../resources/testharnessreport.js"></script> |
| <script> |
| const whlslTests = {}; |
| |
| whlslTests.doWhile = async () => |
| { |
| let program = ` |
| int foo1(int x) |
| { |
| int y = 7; |
| do { |
| y = 8; |
| break; |
| } while (x < 10); |
| return y; |
| } |
| int foo2(int x) |
| { |
| int y = 7; |
| do { |
| y = 8; |
| break; |
| } while (y == 7); |
| return y; |
| } |
| int foo3(int x) |
| { |
| int sum = 0; |
| do { |
| if (x == 11) { |
| x = 15; |
| continue; |
| } |
| sum = sum + x; |
| x = x + 1; |
| } while (x < 13); |
| return sum; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo1", [makeInt(1)]), 8); |
| assert_equals(await callIntFunction(program, "foo1", [makeInt(11)]), 8); |
| assert_equals(await callIntFunction(program, "foo2", [makeInt(1)]), 8); |
| assert_equals(await callIntFunction(program, "foo3", [makeInt(9)]), 19); |
| } |
| |
| whlslTests.simpleWhile = async () => |
| { |
| let program = ` |
| int foo(int x) |
| { |
| while (x < 13) |
| x = x * 2; |
| return x; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo", [makeInt(1)]), 16); |
| } |
| |
| runTests(whlslTests); |
| </script> |
| </html> |