Skip to content

Commit

Permalink
Fix some core tests
Browse files Browse the repository at this point in the history
  • Loading branch information
limzykenneth committed Dec 2, 2024
1 parent ef31f7b commit 76e3ad7
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 92 deletions.
71 changes: 31 additions & 40 deletions test/unit/core/2d_primitives.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,63 @@
import p5 from '../../../src/app.js';
import { mockP5, mockP5Prototype } from '../../js/mocks';
import primitives from '../../../src/shape/2d_primitives';

suite('2D Primitives', function() {
var myp5;

beforeAll(function() {
new p5(function(p) {
p.setup = function() {
myp5 = p;
};
});
});

afterAll(async function() {
await myp5.remove();
primitives(mockP5, mockP5Prototype);
});

suite('p5.prototype.arc', function() {
test('should be a function', function() {
assert.ok(myp5.arc);
assert.typeOf(myp5.arc, 'function');
assert.ok(mockP5Prototype.arc);
assert.typeOf(mockP5Prototype.arc, 'function');
});
});

suite('p5.prototype.ellipse', function() {
test('should be a function', function() {
assert.ok(myp5.ellipse);
assert.typeOf(myp5.ellipse, 'function');
assert.ok(mockP5Prototype.ellipse);
assert.typeOf(mockP5Prototype.ellipse, 'function');
});
});

suite('p5.prototype.line', function() {
test('should be a function', function() {
assert.ok(myp5.line);
assert.typeOf(myp5.line, 'function');
assert.ok(mockP5Prototype.line);
assert.typeOf(mockP5Prototype.line, 'function');
});
});

suite('p5.prototype.point', function() {
test('should be a function', function() {
assert.ok(myp5.point);
assert.typeOf(myp5.point, 'function');
assert.ok(mockP5Prototype.point);
assert.typeOf(mockP5Prototype.point, 'function');
});
});

suite('p5.prototype.quad', function() {
test('should be a function', function() {
assert.ok(myp5.quad);
assert.typeOf(myp5.quad, 'function');
assert.ok(mockP5Prototype.quad);
assert.typeOf(mockP5Prototype.quad, 'function');
});
});

suite('p5.prototype.rect', function() {
test('should be a function', function() {
assert.ok(myp5.rect);
assert.typeOf(myp5.rect, 'function');
assert.ok(mockP5Prototype.rect);
assert.typeOf(mockP5Prototype.rect, 'function');
});
});

suite('p5.prototype.triangle', function() {
test('should be a function', function() {
assert.ok(myp5.triangle);
assert.typeOf(myp5.triangle, 'function');
assert.ok(mockP5Prototype.triangle);
assert.typeOf(mockP5Prototype.triangle, 'function');
});
});
suite('p5.prototype.square', function() {
test('should be a function', function() {
assert.ok(myp5.square);
assert.typeOf(myp5.square, 'function');
assert.ok(mockP5Prototype.square);
assert.typeOf(mockP5Prototype.square, 'function');
});
});

Expand All @@ -75,7 +66,7 @@ suite('2D Primitives', function() {
var i, j, angles;
for (i = -2; i <= 2; i++) {
for (j = -2; j <= 2; j++) {
angles = myp5._normalizeArcAngles(
angles = mockP5Prototype._normalizeArcAngles(
2 * Math.PI * i,
2 * Math.PI * j,
500,
Expand All @@ -92,7 +83,7 @@ suite('2D Primitives', function() {
var i, j, angles;
for (i = -2; i <= 2; i++) {
for (j = -2; j <= 2; j++) {
angles = myp5._normalizeArcAngles(
angles = mockP5Prototype._normalizeArcAngles(
2 * Math.PI * i + 1,
2 * Math.PI * j + 1,
500,
Expand All @@ -109,7 +100,7 @@ suite('2D Primitives', function() {
var i, j, angles;
for (i = -2; i <= 2; i++) {
for (j = -2; j <= 2; j++) {
angles = myp5._normalizeArcAngles(
angles = mockP5Prototype._normalizeArcAngles(
2 * Math.PI * i - 0.000001,
2 * Math.PI * j + 0.000001,
500,
Expand All @@ -126,7 +117,7 @@ suite('2D Primitives', function() {
var i, j, angles;
for (i = -2; i <= 2; i++) {
for (j = -2; j <= 2; j++) {
angles = myp5._normalizeArcAngles(
angles = mockP5Prototype._normalizeArcAngles(
2 * Math.PI * i + 0.000001,
2 * Math.PI * j - 0.000001,
500,
Expand All @@ -143,7 +134,7 @@ suite('2D Primitives', function() {
var i, j, angles;
for (i = -2; i <= 2; i++) {
for (j = -2; j <= 2; j++) {
angles = myp5._normalizeArcAngles(
angles = mockP5Prototype._normalizeArcAngles(
2 * Math.PI * i + 0.999999,
2 * Math.PI * j + 1.000001,
500,
Expand All @@ -160,7 +151,7 @@ suite('2D Primitives', function() {
var i, j, angles;
for (i = -2; i <= 2; i++) {
for (j = -2; j <= 2; j++) {
angles = myp5._normalizeArcAngles(
angles = mockP5Prototype._normalizeArcAngles(
2 * Math.PI * i + 1.000001,
2 * Math.PI * j + 0.999999,
500,
Expand All @@ -177,7 +168,7 @@ suite('2D Primitives', function() {
var i, j, angles;
for (i = -2; i <= 2; i++) {
for (j = -2; j <= 2; j++) {
angles = myp5._normalizeArcAngles(
angles = mockP5Prototype._normalizeArcAngles(
2 * Math.PI * i - 0.1,
2 * Math.PI * j + 0.1,
500,
Expand All @@ -194,7 +185,7 @@ suite('2D Primitives', function() {
var i, j, angles;
for (i = -2; i <= 2; i++) {
for (j = -2; j <= 2; j++) {
angles = myp5._normalizeArcAngles(
angles = mockP5Prototype._normalizeArcAngles(
2 * Math.PI * i + 0.1,
2 * Math.PI * j - 0.1,
500,
Expand All @@ -211,7 +202,7 @@ suite('2D Primitives', function() {
var i, j, angles;
for (i = -2; i <= 2; i++) {
for (j = -2; j <= 2; j++) {
angles = myp5._normalizeArcAngles(
angles = mockP5Prototype._normalizeArcAngles(
2 * Math.PI * i + 0.9,
2 * Math.PI * j + 1.1,
500,
Expand All @@ -228,7 +219,7 @@ suite('2D Primitives', function() {
var i, j, angles;
for (i = -2; i <= 2; i++) {
for (j = -2; j <= 2; j++) {
angles = myp5._normalizeArcAngles(
angles = mockP5Prototype._normalizeArcAngles(
2 * Math.PI * i + 1.1,
2 * Math.PI * j + 0.9,
500,
Expand All @@ -245,7 +236,7 @@ suite('2D Primitives', function() {
var i, j, angles;
for (i = -2; i <= 2; i++) {
for (j = -2; j <= 2; j++) {
angles = myp5._normalizeArcAngles(
angles = mockP5Prototype._normalizeArcAngles(
2 * Math.PI * (i + 40 / 360),
2 * Math.PI * (j + 230 / 360),
500,
Expand All @@ -262,7 +253,7 @@ suite('2D Primitives', function() {
var i, j, angles;
for (i = -2; i <= 2; i++) {
for (j = -2; j <= 2; j++) {
angles = myp5._normalizeArcAngles(
angles = mockP5Prototype._normalizeArcAngles(
2 * Math.PI * (i + 320 / 360),
2 * Math.PI * (j + 130 / 360),
500,
Expand Down
43 changes: 17 additions & 26 deletions test/unit/core/attributes.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,57 @@
import p5 from '../../../src/app.js';
import { mockP5, mockP5Prototype } from '../../js/mocks';
import attributes from '../../../src/shape/attributes';

suite('Attributes', function() {
var myp5;

beforeAll(function() {
new p5(function(p) {
p.setup = function() {
myp5 = p;
};
});
});

afterAll(function() {
myp5.remove();
attributes(mockP5, mockP5Prototype);
});

suite('p5.prototype.ellipseMode', function() {
test('should be a function', function() {
assert.ok(myp5.ellipseMode);
assert.typeOf(myp5.ellipseMode, 'function');
assert.ok(mockP5Prototype.ellipseMode);
assert.typeOf(mockP5Prototype.ellipseMode, 'function');
});
});

suite('p5.prototype.rectMode', function() {
test('should be a function', function() {
assert.ok(myp5.rectMode);
assert.typeOf(myp5.rectMode, 'function');
assert.ok(mockP5Prototype.rectMode);
assert.typeOf(mockP5Prototype.rectMode, 'function');
});
});

suite('p5.prototype.noSmooth', function() {
test('should be a function', function() {
assert.ok(myp5.noSmooth);
assert.typeOf(myp5.noSmooth, 'function');
assert.ok(mockP5Prototype.noSmooth);
assert.typeOf(mockP5Prototype.noSmooth, 'function');
});
});

suite('p5.prototype.smooth', function() {
test('should be a function', function() {
assert.ok(myp5.smooth);
assert.typeOf(myp5.smooth, 'function');
assert.ok(mockP5Prototype.smooth);
assert.typeOf(mockP5Prototype.smooth, 'function');
});
});

suite('p5.prototype.strokeCap', function() {
test('should be a function', function() {
assert.ok(myp5.strokeCap);
assert.typeOf(myp5.strokeCap, 'function');
assert.ok(mockP5Prototype.strokeCap);
assert.typeOf(mockP5Prototype.strokeCap, 'function');
});
});

suite('p5.prototype.strokeJoin', function() {
test('should be a function', function() {
assert.ok(myp5.strokeJoin);
assert.typeOf(myp5.strokeJoin, 'function');
assert.ok(mockP5Prototype.strokeJoin);
assert.typeOf(mockP5Prototype.strokeJoin, 'function');
});
});

suite('p5.prototype.strokeWeight', function() {
test('should be a function', function() {
assert.ok(myp5.strokeWeight);
assert.typeOf(myp5.strokeWeight, 'function');
assert.ok(mockP5Prototype.strokeWeight);
assert.typeOf(mockP5Prototype.strokeWeight, 'function');
});
});
});
50 changes: 24 additions & 26 deletions test/unit/core/curves.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
import p5 from '../../../src/app.js';
import { mockP5, mockP5Prototype } from '../../js/mocks';
import curves from '../../../src/shape/curves';

suite('Curves', function() {
var myp5;

beforeAll(function() {
new p5(function(p) {
p.setup = function() {
myp5 = p;
};
});
mockP5Prototype._renderer = {
_curveTightness: 0
};
curves(mockP5, mockP5Prototype);
});

afterAll(function() {
myp5.remove();
afterAll(() => {
delete mockP5Prototype._renderer;
});

suite('p5.prototype.bezier', function() {
test('should be a function', function() {
assert.ok(myp5.bezier);
assert.typeOf(myp5.bezier, 'function');
assert.ok(mockP5Prototype.bezier);
assert.typeOf(mockP5Prototype.bezier, 'function');
});
});

suite('p5.prototype.bezierPoint', function() {
var result;
test('should be a function', function() {
assert.ok(myp5.bezierPoint);
assert.typeOf(myp5.bezierPoint, 'function');
assert.ok(mockP5Prototype.bezierPoint);
assert.typeOf(mockP5Prototype.bezierPoint, 'function');
});
test('should return the correct point on a Bezier Curve', function() {
result = myp5.bezierPoint(85, 10, 90, 15, 0.5);
result = mockP5Prototype.bezierPoint(85, 10, 90, 15, 0.5);
assert.equal(result, 50);
assert.notEqual(result, -1);
});
Expand All @@ -38,30 +36,30 @@ suite('Curves', function() {
suite('p5.prototype.bezierTangent', function() {
var result;
test('should be a function', function() {
assert.ok(myp5.bezierTangent);
assert.typeOf(myp5.bezierTangent, 'function');
assert.ok(mockP5Prototype.bezierTangent);
assert.typeOf(mockP5Prototype.bezierTangent, 'function');
});
test('should return the correct point on a Bezier Curve', function() {
result = myp5.bezierTangent(95, 73, 73, 15, 0.5);
result = mockP5Prototype.bezierTangent(95, 73, 73, 15, 0.5);
assert.equal(result, -60);
});
});

suite('p5.prototype.curve', function() {
test('should be a function', function() {
assert.ok(myp5.curve);
assert.typeOf(myp5.curve, 'function');
assert.ok(mockP5Prototype.curve);
assert.typeOf(mockP5Prototype.curve, 'function');
});
});

suite('p5.prototype.curvePoint', function() {
var result;
test('should be a function', function() {
assert.ok(myp5.curvePoint);
assert.typeOf(myp5.curvePoint, 'function');
assert.ok(mockP5Prototype.curvePoint);
assert.typeOf(mockP5Prototype.curvePoint, 'function');
});
test('should return the correct point on a Catmull-Rom Curve', function() {
result = myp5.curvePoint(5, 5, 73, 73, 0.5);
result = mockP5Prototype.curvePoint(5, 5, 73, 73, 0.5);
assert.equal(result, 39);
assert.notEqual(result, -1);
});
Expand All @@ -70,11 +68,11 @@ suite('Curves', function() {
suite('p5.prototype.curveTangent', function() {
var result;
test('should be a function', function() {
assert.ok(myp5.curveTangent);
assert.typeOf(myp5.curveTangent, 'function');
assert.ok(mockP5Prototype.curveTangent);
assert.typeOf(mockP5Prototype.curveTangent, 'function');
});
test('should return the correct point on a Catmull-Rom Curve', function() {
result = myp5.curveTangent(95, 73, 73, 15, 0.5);
result = mockP5Prototype.curveTangent(95, 73, 73, 15, 0.5);
assert.equal(result, 10);
assert.notEqual(result, -1);
});
Expand Down

0 comments on commit 76e3ad7

Please sign in to comment.