From 999c67f2bcc0d3d0e719cb30f2cc96baef08c79c Mon Sep 17 00:00:00 2001 From: peabnuts123 Date: Sun, 30 Dec 2018 16:22:58 +1300 Subject: [PATCH] Adding tests for transformer modules --- src/module/transformer/scalepoint.ts | 6 +- src/module/transformer/translatepoint.ts | 6 +- src/module/transformer/turbulence.ts | 3 +- test/module/transformer/displace.test.ts | 144 ++++++++++++++++++ test/module/transformer/rotatepoint.test.ts | 130 ++++++++++++++++ test/module/transformer/scalepoint.test.ts | 91 +++++++++++ .../module/transformer/translatepoint.test.ts | 88 +++++++++++ test/module/transformer/turbulence.test.ts | 110 +++++++++++++ 8 files changed, 571 insertions(+), 7 deletions(-) create mode 100644 test/module/transformer/displace.test.ts create mode 100644 test/module/transformer/rotatepoint.test.ts create mode 100644 test/module/transformer/scalepoint.test.ts create mode 100644 test/module/transformer/translatepoint.test.ts create mode 100644 test/module/transformer/turbulence.test.ts diff --git a/src/module/transformer/scalepoint.ts b/src/module/transformer/scalepoint.ts index 3201265..11635b1 100644 --- a/src/module/transformer/scalepoint.ts +++ b/src/module/transformer/scalepoint.ts @@ -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; diff --git a/src/module/transformer/translatepoint.ts b/src/module/transformer/translatepoint.ts index a2d390e..0fdab66 100644 --- a/src/module/transformer/translatepoint.ts +++ b/src/module/transformer/translatepoint.ts @@ -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; diff --git a/src/module/transformer/turbulence.ts b/src/module/transformer/turbulence.ts index 5a0de3a..ecdb5f0 100644 --- a/src/module/transformer/turbulence.ts +++ b/src/module/transformer/turbulence.ts @@ -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(); diff --git a/test/module/transformer/displace.test.ts b/test/module/transformer/displace.test.ts new file mode 100644 index 0000000..9b97286 --- /dev/null +++ b/test/module/transformer/displace.test.ts @@ -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); +} diff --git a/test/module/transformer/rotatepoint.test.ts b/test/module/transformer/rotatepoint.test.ts new file mode 100644 index 0000000..e97bed3 --- /dev/null +++ b/test/module/transformer/rotatepoint.test.ts @@ -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); +} diff --git a/test/module/transformer/scalepoint.test.ts b/test/module/transformer/scalepoint.test.ts new file mode 100644 index 0000000..15b96e2 --- /dev/null +++ b/test/module/transformer/scalepoint.test.ts @@ -0,0 +1,91 @@ +import { expect } from 'chai'; +import { describe, it } from 'mocha'; + +import { Const } from '@app/module/generator'; +import { ScalePoint } from '@app/module/transformer'; + +describe('module/transformer/scalepoint', () => { + it("can construct successfully", () => { + // Setup + const sourceValue = 2; + const sourceModule = new Const(sourceValue); + const xScale = 10; + const yScale = 20; + const zScale = 30; + + // Test + const testFunc = () => { + new ScalePoint(sourceModule, xScale, yScale, zScale); + }; + + // 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 xScale = 10; + const yScale = 20; + const zScale = 30; + + // Test + const mockModule = new ScalePoint(null, xScale, yScale, zScale); + + // 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("calling setScales updates correctly", () => { + // Setup + const mockModule = createMockModule(); + const newXValue = 20; + const newYValue = 30; + const newZValue = 40; + + + // Test + mockModule.setScales(newXValue, newYValue, newZValue); + const updatedXValue = mockModule.xScale; + const updatedYValue = mockModule.yScale; + const updatedZValue = mockModule.zScale; + + // 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 xScale = 10; + const yScale = 20; + const zScale = 30; + + // Test + return new ScalePoint(sourceModule, xScale, yScale, zScale); +} diff --git a/test/module/transformer/translatepoint.test.ts b/test/module/transformer/translatepoint.test.ts new file mode 100644 index 0000000..7aa558a --- /dev/null +++ b/test/module/transformer/translatepoint.test.ts @@ -0,0 +1,88 @@ +import { expect } from 'chai'; +import { describe, it } from 'mocha'; + +import { Const } from '@app/module/generator'; +import { TranslatePoint } from '@app/module/transformer'; + +describe('module/transformer/translatepoint', () => { + it("can construct successfully", () => { + // Setup + const sourceValue = 2; + const sourceModule = new Const(sourceValue); + const xTranslate = 10; + const yTranslate = 20; + const zTranslate = 30; + + // Test + const testFunc = () => { + new TranslatePoint(sourceModule, xTranslate, yTranslate, zTranslate); + }; + + // 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 xTranslate = 10; + const yTranslate = 20; + const zTranslate = 30; + + // Test + const mockModule = new TranslatePoint(null, xTranslate, yTranslate, zTranslate); + + // 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("calling setTranslation updates correctly", () => { + // Setup + const mockModule = createMockModule(); + const newXValue = 20; + const newYValue = 30; + const newZValue = 40; + + // Test + mockModule.setTranslation(newXValue, newYValue, newZValue); + const updatedXValue = mockModule.translateX; + const updatedYValue = mockModule.translateY; + const updatedZValue = mockModule.translateZ; + + // Assert + expect(updatedXValue).to.equal(newXValue); + expect(updatedYValue).to.equal(newYValue); + expect(updatedZValue).to.equal(newZValue); + }); +}); + +function createMockModule() { + const sourceValue = 2; + const sourceModule = new Const(sourceValue); + const xTranslate = 10; + const yTranslate = 20; + const zTranslate = 30; + + return new TranslatePoint(sourceModule, xTranslate, yTranslate, zTranslate); +} diff --git a/test/module/transformer/turbulence.test.ts b/test/module/transformer/turbulence.test.ts new file mode 100644 index 0000000..897f1a3 --- /dev/null +++ b/test/module/transformer/turbulence.test.ts @@ -0,0 +1,110 @@ +import { expect } from 'chai'; +import { describe, it } from 'mocha'; + +import { Const } from '@app/module/generator'; +import { Turbulence } from '@app/module/transformer'; + +describe('module/transformer/turbulence', () => { + it("can construct successfully", () => { + // Setup + const sourceValue = 2; + const sourceModule = new Const(sourceValue); + const frequency = 1.5; + const power = 1.5; + const roughness = 4; + const seed = 18; + + // Test + const testFunc = () => { + new Turbulence(sourceModule, frequency, power, roughness, seed); + }; + + // 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 xTranslate = 10; + const yTranslate = 20; + const zTranslate = 30; + + // Test + const mockModule = new Turbulence(null, xTranslate, yTranslate, zTranslate); + + // 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 frequency updates correctly", () => { + // Setup + const mockModule = createMockModule(); + const newValue = 2; + + // Test + mockModule.frequency = newValue; + const updatedValue = mockModule.frequency; + + // Assert + expect(updatedValue).to.equal(newValue); + }); + + it("setting roughness updates correctly", () => { + // Setup + const mockModule = createMockModule(); + const newValue = 5; + + // Test + mockModule.roughness = newValue; + const updatedValue = mockModule.roughness; + + // Assert + expect(updatedValue).to.equal(newValue); + }); + + it("setting seed updates correctly", () => { + // Setup + const mockModule = createMockModule(); + const newValue = 5; + + // Test + mockModule.seed = newValue; + const updatedValue = mockModule.seed; + + // Assert + expect(updatedValue).to.equal(newValue); + }); +}); + +function createMockModule() { + const sourceValue = 2; + const sourceModule = new Const(sourceValue); + const frequency = 1.5; + const power = 1.5; + const roughness = 4; + const seed = 18; + + return new Turbulence(sourceModule, frequency, power, roughness, seed); +}