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.
- Loading branch information
1 parent
37cb3eb
commit b6738b9
Showing
4 changed files
with
304 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import { Const } from '@app/module/generator'; | ||
import { Blend } from '@app/module/selector'; | ||
|
||
describe('module/selector/blend', () => { | ||
it("can construct successfully", () => { | ||
// Setup | ||
const sourceValueA = 2; | ||
const sourceModuleA = new Const(sourceValueA); | ||
const sourceValueB = 2; | ||
const sourceModuleB = new Const(sourceValueB); | ||
const controlValue = 0.5; | ||
const controlModule = new Const(controlValue); | ||
|
||
// Test | ||
const testFunc = () => { | ||
new Blend([sourceModuleA, sourceModuleB], controlModule); | ||
}; | ||
|
||
// Assert | ||
expect(testFunc).not.to.throw(); | ||
}); | ||
|
||
it("calling getValue with 0 sourceModules throws an error", () => { | ||
// Setup | ||
const x = 10; | ||
const y = 10; | ||
const z = 10; | ||
const controlValue = 0.5; | ||
const controlModule = new Const(controlValue); | ||
const mockModule = new Blend([], controlModule); | ||
|
||
// Test | ||
const testFunc = () => { | ||
mockModule.getValue(x, y, z); | ||
}; | ||
|
||
// Assert | ||
expect(testFunc).to.throw(); | ||
}); | ||
|
||
it("calling getValue with 1 sourceModule throws an error", () => { | ||
// Setup | ||
const x = 10; | ||
const y = 10; | ||
const z = 10; | ||
const sourceValueA = 2; | ||
const sourceModuleA = new Const(sourceValueA); | ||
const controlValue = 0.5; | ||
const controlModule = new Const(controlValue); | ||
const mockModule = new Blend([sourceModuleA], controlModule); | ||
|
||
// Test | ||
const testFunc = () => { | ||
mockModule.getValue(x, y, z); | ||
}; | ||
|
||
// Assert | ||
expect(testFunc).to.throw(); | ||
}); | ||
|
||
it("calling getValue with no controlModule throws an error", () => { | ||
// Setup | ||
const x = 10; | ||
const y = 10; | ||
const z = 10; | ||
const sourceValueA = 2; | ||
const sourceModuleA = new Const(sourceValueA); | ||
const sourceValueB = 2; | ||
const sourceModuleB = new Const(sourceValueB); | ||
const mockModule = new Blend([sourceModuleA, sourceModuleB]); | ||
|
||
// 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() { | ||
const sourceValueA = 2; | ||
const sourceModuleA = new Const(sourceValueA); | ||
const sourceValueB = 2; | ||
const sourceModuleB = new Const(sourceValueB); | ||
const controlValue = 0.5; | ||
const controlModule = new Const(controlValue); | ||
|
||
return new Blend([sourceModuleA, sourceModuleB], controlModule); | ||
} |
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,194 @@ | ||
import { expect } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import { Const } from '@app/module/generator'; | ||
import { Select } from '@app/module/selector'; | ||
|
||
describe('module/selector/select', () => { | ||
it("can construct successfully", () => { | ||
// Setup | ||
const sourceValueA = 2; | ||
const sourceModuleA = new Const(sourceValueA); | ||
const sourceValueB = 2; | ||
const sourceModuleB = new Const(sourceValueB); | ||
const controlValue = 0.5; | ||
const controlModule = new Const(controlValue); | ||
const edgeFalloff = 1; | ||
const lowerBound = -0.5; | ||
const upperBound = 0.5; | ||
|
||
// Test | ||
const testFunc = () => { | ||
new Select([sourceModuleA, sourceModuleB], controlModule, edgeFalloff, lowerBound, upperBound); | ||
}; | ||
|
||
// Assert | ||
expect(testFunc).not.to.throw(); | ||
}); | ||
|
||
it("calling getValue with 0 sourceModules throws an error", () => { | ||
// Setup | ||
const x = 10; | ||
const y = 10; | ||
const z = 10; | ||
const controlValue = 0.5; | ||
const controlModule = new Const(controlValue); | ||
const edgeFalloff = 1; | ||
const lowerBound = -0.5; | ||
const upperBound = 0.5; | ||
|
||
const mockModule = new Select([], controlModule, edgeFalloff, lowerBound, upperBound); | ||
|
||
// Test | ||
const testFunc = () => { | ||
mockModule.getValue(x, y, z); | ||
}; | ||
|
||
// Assert | ||
expect(testFunc).to.throw(); | ||
}); | ||
|
||
it("calling getValue with 1 sourceModule throws an error", () => { | ||
// Setup | ||
const x = 10; | ||
const y = 10; | ||
const z = 10; | ||
const sourceValueA = 2; | ||
const sourceModuleA = new Const(sourceValueA); | ||
const controlValue = 0.5; | ||
const controlModule = new Const(controlValue); | ||
const edgeFalloff = 1; | ||
const lowerBound = -0.5; | ||
const upperBound = 0.5; | ||
|
||
const mockModule = new Select([sourceModuleA], controlModule, edgeFalloff, lowerBound, upperBound); | ||
|
||
// Test | ||
const testFunc = () => { | ||
mockModule.getValue(x, y, z); | ||
}; | ||
|
||
// Assert | ||
expect(testFunc).to.throw(); | ||
}); | ||
|
||
it("calling getValue with no controlModule throws an error", () => { | ||
// Setup | ||
const x = 10; | ||
const y = 10; | ||
const z = 10; | ||
const sourceValueA = 2; | ||
const sourceModuleA = new Const(sourceValueA); | ||
const sourceValueB = 2; | ||
const sourceModuleB = new Const(sourceValueB); | ||
const edgeFalloff = 1; | ||
const lowerBound = -0.5; | ||
const upperBound = 0.5; | ||
|
||
const mockModule = new Select([sourceModuleA, sourceModuleB], null, edgeFalloff, lowerBound, upperBound); | ||
|
||
// 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 edge updates correctly", () => { | ||
// Setup | ||
const newEdgeValue = 0.2; | ||
const mockModule = createMockModule(); | ||
|
||
// Test | ||
mockModule.edge = newEdgeValue; | ||
const updatedEdgeValue = mockModule.edge; | ||
|
||
// Assert | ||
expect(updatedEdgeValue).to.equal(newEdgeValue); | ||
}); | ||
|
||
it("setting lowerBound updates correctly", () => { | ||
// Setup | ||
const newLowerBoundValue = -1; | ||
const mockModule = createMockModule(); | ||
|
||
// Test | ||
mockModule.lowerBound = newLowerBoundValue; | ||
const updatedLowerBoundValue = mockModule.lowerBound; | ||
|
||
// Assert | ||
expect(updatedLowerBoundValue).to.equal(newLowerBoundValue); | ||
}); | ||
|
||
it("setting lowerBound to a value higher than upperBound throws an error", () => { | ||
// Setup | ||
const mockModule = createMockModule(); | ||
const newLowerBoundValue = mockModule.upperBound + 1; | ||
|
||
// Test | ||
const testFunc = () => { | ||
mockModule.lowerBound = newLowerBoundValue; | ||
}; | ||
|
||
// Assert | ||
expect(testFunc).to.throw(); | ||
}); | ||
|
||
it("setting upperBound updates correctly", () => { | ||
// Setup | ||
const newUpperBoundValue = 2; | ||
const mockModule = createMockModule(); | ||
|
||
// Test | ||
mockModule.upperBound = newUpperBoundValue; | ||
const updatedUpperBoundValue = mockModule.upperBound; | ||
|
||
// Assert | ||
expect(updatedUpperBoundValue).to.equal(newUpperBoundValue); | ||
}); | ||
|
||
it("setting upperBound to a value higher than lowerBound throws an error", () => { | ||
// Setup | ||
const mockModule = createMockModule(); | ||
const newUpperBoundValue = mockModule.lowerBound - 1; | ||
|
||
// Test | ||
const testFunc = () => { | ||
mockModule.upperBound = newUpperBoundValue; | ||
}; | ||
|
||
// Assert | ||
expect(testFunc).to.throw(); | ||
}); | ||
}); | ||
|
||
function createMockModule() { | ||
const sourceValueA = 2; | ||
const sourceModuleA = new Const(sourceValueA); | ||
const sourceValueB = 2; | ||
const sourceModuleB = new Const(sourceValueB); | ||
const controlValue = 0.5; | ||
const controlModule = new Const(controlValue); | ||
const edgeFalloff = 1; | ||
const lowerBound = -0.5; | ||
const upperBound = 0.5; | ||
|
||
// Test | ||
return new Select([sourceModuleA, sourceModuleB], controlModule, edgeFalloff, lowerBound, upperBound); | ||
} |