Skip to content

Commit 88e5a23

Browse files
author
Aayushdev18
committed
Improve OR and AND operator tests per maintainer feedback
- OR test now verifies both left and top edges are red - AND test now tests corners, with bottom-right being white and others black
1 parent 38f2c7a commit 88e5a23

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

test/unit/webgl/p5.Shader.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -733,19 +733,21 @@ suite('p5.Shader', function() {
733733
assert.approximately(centerPixel[0], 255, 5);
734734
assert.approximately(centerPixel[1], 255, 5);
735735
assert.approximately(centerPixel[2], 255, 5);
736-
const edgePixel = myp5.get(5, 25);
737-
assert.approximately(edgePixel[0], 255, 5);
738-
assert.approximately(edgePixel[1], 0, 5);
739-
assert.approximately(edgePixel[2], 0, 5);
736+
const leftEdgePixel = myp5.get(5, 25);
737+
assert.approximately(leftEdgePixel[0], 255, 5);
738+
assert.approximately(leftEdgePixel[1], 0, 5);
739+
assert.approximately(leftEdgePixel[2], 0, 5);
740+
const topEdgePixel = myp5.get(25, 5);
741+
assert.approximately(topEdgePixel[0], 255, 5);
742+
assert.approximately(topEdgePixel[1], 0, 5);
743+
assert.approximately(topEdgePixel[2], 0, 5);
740744
});
741745
test('handle if statement with && (AND) operator', () => {
742746
myp5.createCanvas(50, 50, myp5.WEBGL);
743747
const testShader = myp5.baseMaterialShader().modify(() => {
744-
const condition1 = myp5.uniformFloat(() => 1.0);
745-
const condition2 = myp5.uniformFloat(() => 1.0);
746748
myp5.getPixelInputs(inputs => {
747749
let color = myp5.float(0.0);
748-
if (condition1 > 0.5 && condition2 > 0.5) {
750+
if (inputs.texCoord.x > 0.5 && inputs.texCoord.y > 0.5) {
749751
color = myp5.float(1.0);
750752
}
751753
inputs.color = [color, color, color, 1.0];
@@ -755,10 +757,22 @@ suite('p5.Shader', function() {
755757
myp5.noStroke();
756758
myp5.shader(testShader);
757759
myp5.plane(myp5.width, myp5.height);
758-
const pixelColor = myp5.get(25, 25);
759-
assert.approximately(pixelColor[0], 255, 5);
760-
assert.approximately(pixelColor[1], 255, 5);
761-
assert.approximately(pixelColor[2], 255, 5);
760+
const bottomRightPixel = myp5.get(45, 45);
761+
assert.approximately(bottomRightPixel[0], 255, 5);
762+
assert.approximately(bottomRightPixel[1], 255, 5);
763+
assert.approximately(bottomRightPixel[2], 255, 5);
764+
const topLeftPixel = myp5.get(5, 5);
765+
assert.approximately(topLeftPixel[0], 0, 5);
766+
assert.approximately(topLeftPixel[1], 0, 5);
767+
assert.approximately(topLeftPixel[2], 0, 5);
768+
const topRightPixel = myp5.get(45, 5);
769+
assert.approximately(topRightPixel[0], 0, 5);
770+
assert.approximately(topRightPixel[1], 0, 5);
771+
assert.approximately(topRightPixel[2], 0, 5);
772+
const bottomLeftPixel = myp5.get(5, 45);
773+
assert.approximately(bottomLeftPixel[0], 0, 5);
774+
assert.approximately(bottomLeftPixel[1], 0, 5);
775+
assert.approximately(bottomLeftPixel[2], 0, 5);
762776
});
763777
// Keep one direct API test for completeness
764778
test('handle direct StrandsIf API usage', () => {

0 commit comments

Comments
 (0)