blob: 7e6a9b94e3aa772bfdd8630ee12eb0efc6295456 [file] [log] [blame]
<!DOCTYPE html>
<html>
<meta charset=utf-8>
<meta name="timeout" content="long">
<title>Div.</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.vectorDiv = async () => {
const program = `
float foo() {
float2 x = float2(10, 30);
float2 y = float2(5, 10);
float2 r = x / y;
return r.x / r.y;
}
`;
assert_approx_equals(await callFloatFunction(program, "foo", []), 2/3, epsilon);
};
whlslTests.vectorDivWithScalar = async () => {
const program = `
float foo() {
float2 x = float2(10, 25);
float2 r = x / 5.0;
return r.x / r.y;
}
`;
assert_approx_equals(await callFloatFunction(program, "foo", []), 2/5, epsilon);
};
whlslTests.vectorDivWithScalar2 = async () => {
const program = `
float foo() {
float2 x = float2(10, 25);
float2 r = 100 / x;
return r.x / r.y;
}
`;
assert_approx_equals(await callFloatFunction(program, "foo", []), 10/4, epsilon);
};
whlslTests.matrixDiv = 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.matrixDivScalar = 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.matrixDivScalar2 = async () => {
const program = `
bool foo() {
float2x2 m;
m[0] = float2(10, 20);
m[1] = float2(25, 50);
m = 100.0 / m;
if (m[0][0] == 10.0 && m[0][1] == 5.0 && m[1][0] == 4.0 && m[1][1] == 2.0)
return true;
return false;
}
`;
assert_equals(await callBoolFunction(program, "foo", []), true);
};
runTests(whlslTests);
</script>
</html>