Skip to content

Commit

Permalink
Adding tests for transformer modules
Browse files Browse the repository at this point in the history
  • Loading branch information
peabnuts123 committed Dec 30, 2018
1 parent b6738b9 commit 999c67f
Show file tree
Hide file tree
Showing 8 changed files with 571 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/module/transformer/scalepoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class ScalePoint {
public static DEFAULT_SCALE_POINT_Z = 1.0;

private sourceModule: any;
private xScale: number;
private yScale: number;
private zScale: number;
public xScale: number;
public yScale: number;
public zScale: number;

constructor(sourceModule?: any, xScale?: number, yScale?: number, zScale?: number) {
this.sourceModule = sourceModule || null;
Expand Down
6 changes: 3 additions & 3 deletions src/module/transformer/translatepoint.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class TranslatePoint {
private sourceModule: any;
private translateX: number;
private translateY: number;
private translateZ: number;
public translateX: number;
public translateY: number;
public translateZ: number;

constructor(sourceModule?: any, translateX?: number, translateY?: number, translateZ?: number) {
this.sourceModule = sourceModule || null;
Expand Down
3 changes: 2 additions & 1 deletion src/module/transformer/turbulence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class Turbulence {
private xDistortModule: Perlin;
private yDistortModule: Perlin;
private zDistortModule: Perlin;
private power: number;

public power: number;

constructor(sourceModule?: any, frequency?: number, power?: number, roughness?: number, seed?: number) {
this.xDistortModule = new Perlin();
Expand Down
144 changes: 144 additions & 0 deletions test/module/transformer/displace.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import { Const } from '@app/module/generator';
import { Displace } from '@app/module/transformer';

describe('module/transformer/displace', () => {
it("can construct successfully", () => {
// Setup
const sourceValue = 2;
const sourceModule = new Const(sourceValue);
const xValue = 1;
const xModule = new Const(xValue);
const yValue = 2;
const yModule = new Const(yValue);
const zValue = 3;
const zModule = new Const(zValue);

// Test
const testFunc = () => {
new Displace(sourceModule, xModule, yModule, zModule);
};

// Assert
expect(testFunc).not.to.throw();
});

it("calling getValue without a sourceModule throws an error", () => {
// Setup
const x = 10;
const y = 10;
const z = 10;
const xValue = 1;
const xModule = new Const(xValue);
const yValue = 2;
const yModule = new Const(yValue);
const zValue = 3;
const zModule = new Const(zValue);
const mockModule = new Displace(null, xModule, yModule, zModule);

// Test
const testFunc = () => {
mockModule.getValue(x, y, z);
};

// Assert
expect(testFunc).to.throw();
});

it("calling getValue without an xModule throws an error", () => {
// Setup
const x = 10;
const y = 10;
const z = 10;
const sourceValue = 1;
const sourceModule = new Const(sourceValue);
const yValue = 2;
const yModule = new Const(yValue);
const zValue = 3;
const zModule = new Const(zValue);
const mockModule = new Displace(sourceModule, null, yModule, zModule);

// Test
const testFunc = () => {
mockModule.getValue(x, y, z);
};

// Assert
expect(testFunc).to.throw();
});

it("calling getValue without a yModule throws an error", () => {
// Setup
const x = 10;
const y = 10;
const z = 10;
const sourceValue = 1;
const sourceModule = new Const(sourceValue);
const xValue = 2;
const xModule = new Const(xValue);
const zValue = 3;
const zModule = new Const(zValue);
const mockModule = new Displace(sourceModule, xModule, null, zModule);

// Test
const testFunc = () => {
mockModule.getValue(x, y, z);
};

// Assert
expect(testFunc).to.throw();
});

it("calling getValue without a zModule throws an error", () => {
// Setup
const x = 10;
const y = 10;
const z = 10;
const sourceValue = 1;
const sourceModule = new Const(sourceValue);
const xValue = 2;
const xModule = new Const(xValue);
const yValue = 3;
const yModule = new Const(yValue);
const mockModule = new Displace(sourceModule, xModule, yModule, null);

// Test
const testFunc = () => {
mockModule.getValue(x, y, z);
};

// Assert
expect(testFunc).to.throw();
});

it("calling getValue returns a number", () => {
// Setup
const x = 10;
const y = 10;
const z = 10;
const mockModule = createMockModule();

// Test
const value = mockModule.getValue(x, y, z);

// Assert
expect(value).to.be.ok;
});
});

function createMockModule() {
// Setup
const sourceValue = 2;
const sourceModule = new Const(sourceValue);
const xValue = 1;
const xModule = new Const(xValue);
const yValue = 2;
const yModule = new Const(yValue);
const zValue = 3;
const zModule = new Const(zValue);

// Test
return new Displace(sourceModule, xModule, yModule, zModule);
}
130 changes: 130 additions & 0 deletions test/module/transformer/rotatepoint.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { expect } from 'chai';
import { describe, it } from 'mocha';

import { Const } from '@app/module/generator';
import { RotatePoint } from '@app/module/transformer';

describe('module/transformer/rotatepoint', () => {
it("can construct successfully", () => {
// Setup
const sourceValue = 2;
const sourceModule = new Const(sourceValue);
const xAngle = 10;
const yAngle = 20;
const zAngle = 30;

// Test
const testFunc = () => {
new RotatePoint(sourceModule, xAngle, yAngle, zAngle);
};

// Assert
expect(testFunc).not.to.throw();
});

it("calling getValue without a sourceModule throws an error", () => {
// Setup
const x = 10;
const y = 10;
const z = 10;
const xAngle = 10;
const yAngle = 20;
const zAngle = 30;

// Test
const mockModule = new RotatePoint(null, xAngle, yAngle, zAngle);

// Test
const testFunc = () => {
mockModule.getValue(x, y, z);
};

// Assert
expect(testFunc).to.throw();
});

it("calling getValue returns a number", () => {
// Setup
const x = 10;
const y = 10;
const z = 10;
const mockModule = createMockModule();

// Test
const value = mockModule.getValue(x, y, z);

// Assert
expect(value).to.be.ok;
});

it("setting xAngle updates correctly", () => {
// Setup
const mockModule = createMockModule();
const newValue = 20;

// Test
mockModule.xAngle = newValue;
const updatedValue = mockModule.xAngle;

// Assert
expect(updatedValue).to.equal(newValue);
});

it("setting yAngle updates correctly", () => {
// Setup
const mockModule = createMockModule();
const newValue = 20;

// Test
mockModule.yAngle = newValue;
const updatedValue = mockModule.yAngle;

// Assert
expect(updatedValue).to.equal(newValue);
});

it("setting zAngle updates correctly", () => {
// Setup
const mockModule = createMockModule();
const newValue = 20;

// Test
mockModule.zAngle = newValue;
const updatedValue = mockModule.zAngle;

// Assert
expect(updatedValue).to.equal(newValue);
});

it("calling setAngles updates correctly", () => {
// Setup
const mockModule = createMockModule();
const newXValue = 20;
const newYValue = 30;
const newZValue = 40;


// Test
mockModule.setAngles(newXValue, newYValue, newZValue);
const updatedXValue = mockModule.xAngle;
const updatedYValue = mockModule.yAngle;
const updatedZValue = mockModule.zAngle;

// Assert
expect(updatedXValue).to.equal(newXValue);
expect(updatedYValue).to.equal(newYValue);
expect(updatedZValue).to.equal(newZValue);
});
});

function createMockModule() {
// Setup
const sourceValue = 2;
const sourceModule = new Const(sourceValue);
const xAngle = 10;
const yAngle = 20;
const zAngle = 30;

// Test
return new RotatePoint(sourceModule, xAngle, yAngle, zAngle);
}

0 comments on commit 999c67f

Please sign in to comment.