X-Git-Url: https://git.yukkurigames.com/?a=blobdiff_plain;f=tests%2Fstring-lerp.js;h=f2fb88dc5a46af696d10f8605cea3cd7ca7e6eb1;hb=bf06839ad7c1952c807da031f82d83e61280bc04;hp=7cee7d175b106f9c312e32109b86a6ebdc20c133;hpb=f037d43269bdb28acf28500ce24d2bef1e011a75;p=string-lerp.git diff --git a/tests/string-lerp.js b/tests/string-lerp.js index 7cee7d1..f2fb88d 100644 --- a/tests/string-lerp.js +++ b/tests/string-lerp.js @@ -152,11 +152,16 @@ JS.Test.describe('numeric lerp', function () { with (this) { it("rounds integers", function () { with (this) { assertEqual("12", lerp("0", "100", 0.123)); - assertEqual("12.3", lerp("0", "100.0", 0.123)); + assertEqual("12.3", lerp("0.0", "100.0", 0.123)); assertEqual("12.3", lerp("0.0", "100", 0.123)); assertEqual("12.3", lerp("0.0", "100.0", 0.123)); }}); + it("thinks about precision", function () { with (this) { + assertEqual("12.30", lerp("0.00", "100.00", 0.123)); + assertEqual("12.300", lerp("0.000", "100.000", 0.123)); + }}); + it("computes parameters outside [0, 1]", function () { with (this) { assertEqual("Giving 110%", lerp("Giving 0%", "Giving 100%", 1.1)); }}); @@ -169,3 +174,36 @@ JS.Test.describe('numeric lerp', function () { with (this) { assertEqual("Chapter 5. The sky was rgb(0, 0, 128).", lerp(A, B, 0.5)); }}); }}); + +JS.Test.describe('fast lerp', function () { with (this) { + var lerp = m.lerp; + var A = "Do you like green eggs and ham?"; + var B = "I do not like them, Sam-I-am."; + + it("handles empty strings", function () { with (this) { + assertEqual("", lerp("", "", -1)); + assertEqual("", lerp("", "", 0)); + assertEqual("", lerp("", "", 0.5)); + assertEqual("", lerp("", "", 1)); + assertEqual("", lerp("", "", 2)); + }}); + + it("maintains identity", function () { with (this) { + for (var i = -1; i < 2; i += 1/1024) { + assertEqual(A, lerp(A, A, i)); + assertEqual(B, lerp(B, B, i)); + } + }}); + + it("handles lows", function () { with (this) { + assertEqual(A, lerp(A, B, -Infinity)); + assertEqual(A, lerp(A, B, -1)); + assertEqual(A, lerp(A, B, 0)); + }}); + + it("handles highs", function () { with (this) { + assertEqual(B, lerp(A, B, 1)); + assertEqual(B, lerp(A, B, 2)); + assertEqual(B, lerp(A, B, Infinity)); + }}); +}});