Skip to content

Commit

Permalink
Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Garima3110 committed Aug 5, 2024
1 parent 4366334 commit eeed9c9
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/unit/core/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,4 +236,41 @@ suite('Environment', function() {
assert.isNumber(myp5.displayDensity(), pd);
});
});

suite('2D context test', function() {
beforeEach(function() {
myp5.createCanvas(100, 100);
});

test('worldToScreen for 2D context', function() {
let worldPos = myp5.createVector(50, 50);
let screenPos = myp5.worldToScreen(worldPos);
assert.closeTo(screenPos.x, 50, 0.1);
assert.closeTo(screenPos.y, 50, 0.1);
});

});

suite('3D context test', function() {
beforeEach(function() {
myp5.createCanvas(100, 100, myp5.WEBGL);
});

test('worldToScreen for 3D context', function() {
let worldPos = myp5.createVector(0, 0, 0);
let screenPos = myp5.worldToScreen(worldPos);
assert.isTrue(screenPos.x >= 0 && screenPos.x <= 100);
assert.isTrue(screenPos.y >= 0 && screenPos.y <= 100);
});

test('worldToScreen with rotation', function() {
myp5.push();
myp5.rotateY(myp5.PI / 2);
let worldPos = myp5.createVector(50, 0, 0);
let screenPos = myp5.worldToScreen(worldPos);
myp5.pop();
assert.isTrue(screenPos.x >= 0 && screenPos.x <= 100);
assert.isTrue(screenPos.y >= 0 && screenPos.y <= 100);
});
});
});

0 comments on commit eeed9c9

Please sign in to comment.