forked from jmcneese/libnoise.js
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding tests for transformer modules
- Loading branch information
1 parent
b6738b9
commit 999c67f
Showing
8 changed files
with
571 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.