-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start replacing spec tests with minitest
- Loading branch information
monkstone
committed
Sep 20, 2015
1 parent
658f038
commit c780a07
Showing
8 changed files
with
301 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
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,36 @@ | ||
gem 'minitest' # don't use bundled minitest | ||
require 'java' | ||
require 'minitest/autorun' | ||
|
||
require_relative '../lib/rpextras' | ||
require_relative '../lib/jruby_art/helpers/aabb' | ||
|
||
Java::MonkstoneVecmathVec2::Vec2Library.new.load(JRuby.runtime, false) | ||
Java::MonkstoneVecmathVec3::Vec3Library.new.load(JRuby.runtime, false) | ||
|
||
EPSILON ||= 1.0e-04 | ||
|
||
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | ||
|
||
Dir.chdir(File.dirname(__FILE__)) | ||
|
||
class MathToolTest < Minitest::Test | ||
def test_aabb_new | ||
x, y = 1.0000001, 1.01 | ||
a = Vec2D.new(x, y) | ||
assert AaBb.new(center: Vec2D.new, extent: a).kind_of? AaBb | ||
x0, y0 = -4, -4 | ||
a = Vec2D.new(x0, y0) | ||
b = a *= -1 | ||
assert AaBb.from_min_max(min: a, max: b).kind_of? AaBb | ||
x, y = 1.0000001, 1.01 | ||
a = AaBb.new(center: Vec2D.new, extent: Vec2D.new(x, y)) | ||
a.position(Vec2D.new(4, 6)) | ||
assert a.center == Vec2D.new(4, 6) | ||
x, y = 1.0000001, 1.01 | ||
a = AaBb.new(center: Vec2D.new, extent: Vec2D.new(x, y)) | ||
a.position(Vec2D.new(4, 6)) { false } | ||
assert a.center == Vec2D.new | ||
end | ||
end | ||
|
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,55 @@ | ||
gem 'minitest' # don't use bundled minitest | ||
require 'java' | ||
require 'minitest/autorun' | ||
|
||
require_relative '../lib/jruby_art/helper_methods' | ||
require_relative '../lib/core' | ||
|
||
include Processing::HelperMethods | ||
|
||
EPSILON ||= 1.0e-04 | ||
|
||
Java::Monkstone::MathToolLibrary.new.load(JRuby.runtime, false) | ||
|
||
include Processing::HelperMethods | ||
include Processing::MathTool | ||
|
||
EPSILON ||= 1.0e-04 | ||
|
||
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | ||
|
||
Dir.chdir(File.dirname(__FILE__)) | ||
|
||
class HelperMethodsTest < Minitest::Test | ||
def test_hex_color | ||
col_double = 0.5 | ||
hexcolor = 0xFFCC6600 | ||
dodgy_hexstring = '*56666' | ||
hexstring = '#CC6600' | ||
assert hex_color(col_double) == 0.5, 'double as a color' | ||
assert hex_color(hexcolor) == -3381760, 'hexadecimal fixnum color' | ||
assert hex_color(hexstring) == -3381760, 'hexadecimal string color' | ||
assert_raises(StandardError, 'Dodgy Hexstring') do | ||
hex_color(dodgy_hexstring) | ||
end | ||
end | ||
|
||
def test_dist | ||
ax, ay, bx, by = 0, 0, 1.0, 1.0 | ||
assert dist(ax, ay, bx, by) == Math.sqrt(2), '2D distance' | ||
by = 0.0 | ||
assert dist(ax, ay, bx, by) == 1.0, 'when y dimension is zero' | ||
ax, ay, bx, by = 0, 0, 0.0, 0.0 | ||
assert dist(ax, ay, bx, by) == 0.0, 'when x and y dimension are zero' | ||
ax, ay, bx, by = 1, 1, -2.0, -3.0 | ||
assert dist(ax, ay, bx, by) == 5, 'classic triangle dimensions' | ||
ax, ay, bx, by, cx, cy = -1, -1, 100, 2.0, 3.0, 100 | ||
assert dist(ax, ay, bx, by, cx, cy) == 5, 'classic triangle dimensions' | ||
ax, ay, bx, by, cx, cy = 0, 0, -1.0, -1.0, 0, 0 | ||
assert dist(ax, ay, bx, by, cx, cy) == Math.sqrt(2) | ||
ax, ay, bx, by, cx, cy = 0, 0, 0.0, 0.0, 0, 0 | ||
assert dist(ax, ay, bx, by, cx, cy) == 0.0 | ||
ax, ay, bx, by, cx, cy = 0, 0, 1.0, 0.0, 0, 0 | ||
assert dist(ax, ay, bx, by, cx, cy) == 1.0, 'when x and z dimension are zero' | ||
end | ||
end |
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,75 @@ | ||
gem 'minitest' # don't use bundled minitest | ||
require 'java' | ||
require 'minitest/autorun' | ||
|
||
require_relative '../lib/rpextras' | ||
require_relative '../lib/jruby_art/helper_methods' | ||
|
||
Java::Monkstone::MathToolLibrary.new.load(JRuby.runtime, false) | ||
|
||
include Processing::HelperMethods | ||
include Processing::MathTool | ||
|
||
EPSILON ||= 1.0e-04 | ||
|
||
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | ||
|
||
Dir.chdir(File.dirname(__FILE__)) | ||
|
||
class MathToolTest < Minitest::Test | ||
def test_map1d | ||
x = [0, 5, 7.5, 10] | ||
range1 = (0..10) | ||
range2 = (100..1) | ||
range3 = (0..10) | ||
range4 = (5..105) | ||
assert map1d(x[0], range1, range2) == 100, 'map to first' | ||
assert map1d(x[1], range1, range2) == 50.5, 'map to reversed intermediate' | ||
assert map1d(x[2], range3, range4) == 80.0, 'map to intermediate' | ||
assert map1d(x[3], range1, range2) == 1, 'map to last' | ||
end | ||
|
||
def test_p5map # as map1d except not using range input | ||
x = [0, 5, 7.5, 10] | ||
range1 = (0..10) | ||
range2 = (100..1) | ||
range3 = (0..10) | ||
range4 = (5..105) | ||
assert p5map(x[0], range1.first, range1.last, range2.first, range2.last) == 100 | ||
assert p5map(x[1], range1.first, range1.last, range2.first, range2.last) == 50.5 | ||
assert p5map(x[2], range3.first, range3.last, range4.first, range4.last) == 80.0 | ||
assert p5map(x[3], range1.first, range1.last, range2.first, range2.last) == 1 | ||
end | ||
|
||
def test_norm | ||
x = [10, 140, 210] | ||
start0, last0 = 30, 200 | ||
start1, last1 = 0, 200 | ||
assert norm(x[0], start0, last0) == -0.11764705882352941, 'unclamped map' | ||
assert norm(x[1], start1, last1) == 0.7, 'map to intermediate' | ||
assert norm(x[2], start1, last1) == 1.05, 'unclamped map' | ||
end | ||
|
||
def test_norm_strict | ||
x = [10, 140, 210] | ||
start0, last0 = 30, 200 | ||
assert norm_strict(x[0], start0, last0) == 0, 'clamped map to 0..1.0' | ||
end | ||
|
||
def test_lerp # behaviour is deliberately different to processing which is unclamped | ||
x = [0.5, 0.8, 2.0] | ||
start0, last0 = 300, 200 | ||
start1, last1 = 0, 200 | ||
assert lerp(start0, last0, x[0]) == 250, 'produces a intermediate value of a reversed range' | ||
assert lerp(start1, last1, x[1]) == 160, 'lerps tp an intermediate value' | ||
assert lerp(start1, last1, x[2]) == 200, 'lerps to the last value of a range' | ||
end | ||
|
||
def test_constrain | ||
x = [15, 2_500, -2_500] | ||
start1, last1 = 0, 200 | ||
assert constrain(x[0], start1, last1) == 15 | ||
assert constrain(x[1], start1, last1) == 200 | ||
assert constrain(x[2], start1, last1) == 0 | ||
end | ||
end |
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,75 @@ | ||
gem 'minitest' # don't use bundled minitest | ||
require 'java' | ||
require 'minitest/autorun' | ||
|
||
require_relative '../lib/rpextras' | ||
require_relative '../lib/jruby_art/helper_methods' | ||
|
||
Java::Monkstone::MathToolLibrary.new.load(JRuby.runtime, false) | ||
|
||
include Processing::HelperMethods | ||
include Processing::MathTool | ||
|
||
EPSILON ||= 1.0e-04 | ||
|
||
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | ||
|
||
Dir.chdir(File.dirname(__FILE__)) | ||
|
||
class Rp5Test < Minitest::Test | ||
def test_map1d | ||
x = [0, 5, 7.5, 10] | ||
range1 = (0..10) | ||
range2 = (100..1) | ||
range3 = (0..10) | ||
range4 = (5..105) | ||
assert map1d(x[0], range1, range2) == 100, 'map to first' | ||
assert map1d(x[1], range1, range2) == 50.5, 'map to reversed intermediate' | ||
assert map1d(x[2], range3, range4) == 80.0, 'map to intermediate' | ||
assert map1d(x[3], range1, range2) == 1, 'map to last' | ||
end | ||
|
||
def test_p5map # as map1d except not using range input | ||
x = [0, 5, 7.5, 10] | ||
range1 = (0..10) | ||
range2 = (100..1) | ||
range3 = (0..10) | ||
range4 = (5..105) | ||
assert p5map(x[0], range1.first, range1.last, range2.first, range2.last) == 100 | ||
assert p5map(x[1], range1.first, range1.last, range2.first, range2.last) == 50.5 | ||
assert p5map(x[2], range3.first, range3.last, range4.first, range4.last) == 80.0 | ||
assert p5map(x[3], range1.first, range1.last, range2.first, range2.last) == 1 | ||
end | ||
|
||
def test_norm | ||
x = [10, 140, 210] | ||
start0, last0 = 30, 200 | ||
start1, last1 = 0, 200 | ||
assert norm(x[0], start0, last0) == -0.11764705882352941, 'unclamped map' | ||
assert norm(x[1], start1, last1) == 0.7, 'map to intermediate' | ||
assert norm(x[2], start1, last1) == 1.05, 'unclamped map' | ||
end | ||
|
||
def test_norm_strict | ||
x = [10, 140, 210] | ||
start0, last0 = 30, 200 | ||
assert norm_strict(x[0], start0, last0) == 0, 'clamped map to 0..1.0' | ||
end | ||
|
||
def test_lerp # behaviour is deliberately different to processing which is unclamped | ||
x = [0.5, 0.8, 2.0] | ||
start0, last0 = 300, 200 | ||
start1, last1 = 0, 200 | ||
assert lerp(start0, last0, x[0]) == 250, 'produces a intermediate value of a reversed range' | ||
assert lerp(start1, last1, x[1]) == 160, 'lerps tp an intermediate value' | ||
assert lerp(start1, last1, x[2]) == 200, 'lerps to the last value of a range' | ||
end | ||
|
||
def test_constrain | ||
x = [15, 2_500, -2_500] | ||
start1, last1 = 0, 200 | ||
assert constrain(x[0], start1, last1) == 15 | ||
assert constrain(x[1], start1, last1) == 200 | ||
assert constrain(x[2], start1, last1) == 0 | ||
end | ||
end |