| <!DOCTYPE html> |
| <html> |
| <meta charset=utf-8> |
| <meta name="timeout" content="long"> |
| <title>Times.</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 = {}; |
| const epsilon = 0.0001; |
| |
| whlslTests.vectorTimes = async () => { |
| const program = ` |
| float foo() { |
| float2 x = float2(2, 5); |
| float2 y = float2(3, 10); |
| float2 r = y * x; |
| return r.x / r.y; |
| } |
| `; |
| assert_approx_equals(await callFloatFunction(program, "foo", []), 6/50, epsilon); |
| }; |
| |
| whlslTests.vectorTimesWithScalar = async () => { |
| const program = ` |
| float foo() { |
| float2 x = float2(10, 20); |
| float2 r = x * 2.0; |
| return r.x * r.y; |
| } |
| `; |
| assert_approx_equals(await callFloatFunction(program, "foo", []), 20 * 40, epsilon); |
| }; |
| |
| whlslTests.vectorTimesWithScalar2 = async () => { |
| const program = ` |
| float foo() { |
| float2 x = float2(10, 20); |
| float2 r = 2.0 * x; |
| return r.x * r.y; |
| } |
| `; |
| assert_approx_equals(await callFloatFunction(program, "foo", []), 20 * 40, epsilon); |
| }; |
| |
| whlslTests.matrixTimes = async () => { |
| const program = ` |
| bool foo() { |
| float2x2 m; |
| m[0] = float2(20, 30); |
| m[1] = float2(40, 50); |
| |
| float2x2 m2; |
| m2[0] = float2(-1.0, -1.0); |
| m2[1] = float2(-1.0, -1.0); |
| |
| m = m * m2; |
| |
| if (m[0][0] == -20.0 && m[0][1] == -30.0 && m[1][0] == -40.0 && m[1][1] == -50.0) |
| return true; |
| return false; |
| } |
| `; |
| assert_equals(await callBoolFunction(program, "foo", []), true); |
| }; |
| |
| whlslTests.matrixTimesScalar = async () => { |
| const program = ` |
| bool foo() { |
| float2x2 m; |
| m[0] = float2(20, 30); |
| m[1] = float2(40, 50); |
| |
| m = m * -1.0; |
| |
| if (m[0][0] == -20.0 && m[0][1] == -30.0 && m[1][0] == -40.0 && m[1][1] == -50.0) |
| return true; |
| return false; |
| } |
| `; |
| assert_equals(await callBoolFunction(program, "foo", []), true); |
| }; |
| |
| whlslTests.matrixTimesScalar2 = async () => { |
| const program = ` |
| bool foo() { |
| float2x2 m; |
| m[0] = float2(20, 30); |
| m[1] = float2(40, 50); |
| |
| m = -1.0 * m; |
| |
| if (m[0][0] == -20.0 && m[0][1] == -30.0 && m[1][0] == -40.0 && m[1][1] == -50.0) |
| return true; |
| return false; |
| } |
| `; |
| assert_equals(await callBoolFunction(program, "foo", []), true); |
| }; |
| |
| runTests(whlslTests); |
| </script> |
| </html> |