| <!DOCTYPE html> |
| <html> |
| <meta charset=utf-8> |
| <meta name="timeout" content="long"> |
| <title>Lvalues.</title> |
| <script src="js/whlsl-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.forLoop = async () => |
| { |
| let program = ` |
| int foo1(int x) |
| { |
| int sum = 0; |
| int i; |
| for (i = 0; i < x; i = i + 1) { |
| sum = sum + i; |
| } |
| return sum; |
| } |
| int foo2(int x) |
| { |
| int sum = 0; |
| for (int i = 0; i < x; i = i + 1) { |
| sum = sum + i; |
| } |
| return sum; |
| } |
| int foo3(int x) |
| { |
| int sum = 0; |
| int i = 100; |
| for (int i = 0; i < x; i = i + 1) { |
| sum = sum + i; |
| } |
| return sum; |
| } |
| int foo4(int x) |
| { |
| int sum = 0; |
| for (int i = 0; i < x; i = i + 1) { |
| if (i == 4) |
| continue; |
| sum = sum + i; |
| } |
| return sum; |
| } |
| int foo5(int x) |
| { |
| int sum = 0; |
| for (int i = 0; i < x; i = i + 1) { |
| if (i == 5) |
| break; |
| sum = sum + i; |
| } |
| return sum; |
| } |
| int foo6(int x) |
| { |
| int sum = 0; |
| for (int i = 0; ; i = i + 1) { |
| if (i >= x) |
| break; |
| sum = sum + i; |
| } |
| return sum; |
| } |
| int foo7(int x) |
| { |
| int sum = 0; |
| int i = 0; |
| for ( ; ; i = i + 1) { |
| if (i >= x) |
| break; |
| sum = sum + i; |
| } |
| return sum; |
| } |
| int foo8(int x) |
| { |
| int sum = 0; |
| int i = 0; |
| for ( ; ; ) { |
| if (i >= x) |
| break; |
| sum = sum + i; |
| i = i + 1; |
| } |
| return sum; |
| } |
| `; |
| assert_equals(await callIntFunction(program, "foo1", [makeInt(3)]), 3); |
| assert_equals(await callIntFunction(program, "foo1", [makeInt(4)]), 6); |
| assert_equals(await callIntFunction(program, "foo1", [makeInt(5)]), 10); |
| assert_equals(await callIntFunction(program, "foo2", [makeInt(3)]), 3); |
| assert_equals(await callIntFunction(program, "foo2", [makeInt(4)]), 6); |
| assert_equals(await callIntFunction(program, "foo2", [makeInt(5)]), 10); |
| assert_equals(await callIntFunction(program, "foo3", [makeInt(3)]), 3); |
| assert_equals(await callIntFunction(program, "foo3", [makeInt(4)]), 6); |
| assert_equals(await callIntFunction(program, "foo3", [makeInt(5)]), 10); |
| assert_equals(await callIntFunction(program, "foo4", [makeInt(3)]), 3); |
| assert_equals(await callIntFunction(program, "foo4", [makeInt(4)]), 6); |
| assert_equals(await callIntFunction(program, "foo4", [makeInt(5)]), 6); |
| assert_equals(await callIntFunction(program, "foo4", [makeInt(6)]), 11); |
| assert_equals(await callIntFunction(program, "foo5", [makeInt(3)]), 3); |
| assert_equals(await callIntFunction(program, "foo5", [makeInt(4)]), 6); |
| assert_equals(await callIntFunction(program, "foo5", [makeInt(5)]), 10); |
| assert_equals(await callIntFunction(program, "foo5", [makeInt(6)]), 10); |
| assert_equals(await callIntFunction(program, "foo5", [makeInt(7)]), 10); |
| assert_equals(await callIntFunction(program, "foo6", [makeInt(3)]), 3); |
| assert_equals(await callIntFunction(program, "foo6", [makeInt(4)]), 6); |
| assert_equals(await callIntFunction(program, "foo6", [makeInt(5)]), 10); |
| assert_equals(await callIntFunction(program, "foo6", [makeInt(6)]), 15); |
| assert_equals(await callIntFunction(program, "foo6", [makeInt(7)]), 21); |
| assert_equals(await callIntFunction(program, "foo7", [makeInt(3)]), 3); |
| assert_equals(await callIntFunction(program, "foo7", [makeInt(4)]), 6); |
| assert_equals(await callIntFunction(program, "foo7", [makeInt(5)]), 10); |
| assert_equals(await callIntFunction(program, "foo7", [makeInt(6)]), 15); |
| assert_equals(await callIntFunction(program, "foo7", [makeInt(7)]), 21); |
| assert_equals(await callIntFunction(program, "foo8", [makeInt(3)]), 3); |
| assert_equals(await callIntFunction(program, "foo8", [makeInt(4)]), 6); |
| assert_equals(await callIntFunction(program, "foo8", [makeInt(5)]), 10); |
| assert_equals(await callIntFunction(program, "foo8", [makeInt(6)]), 15); |
| assert_equals(await callIntFunction(program, "foo8", [makeInt(7)]), 21); |
| await checkFail( |
| ` |
| void foo(int x) |
| { |
| for (int i = 0; ; i = i + 1) { |
| break; |
| x = i; |
| } |
| } |
| `); |
| await checkFail( |
| ` |
| int foo(int x) |
| { |
| for ( ; x < 10; ) { |
| return 7; |
| } |
| } |
| `); |
| } |
| |
| runTests(whlslTests); |
| </script> |
| </html> |
| |