UNPKG

fluentnode

Version:

Fluent apis for node (based on the concepts used in C#'s FluentSharp

112 lines (109 loc) 3.51 kB
// Generated by CoffeeScript 1.12.7 (function() { require('../../src/fluentnode'); describe('| js-native | Number', function() { it('add', function() { var original; 1..add().assert_Is(1); (-1).add().assert_Is(-1); 10..add().assert_Is(10); 1..add(0).assert_Is(1); 1..add(4).assert_Is(5); 10..add(-1).assert_Is(9); 10..add(-9).assert_Is(1); original = 1; return using(original, function() { this.add().assert_Is(this); this.assert_Is(1); this.add(9).assert_Is(this + 9); return this.assert_Is(1); }); }); it('dec', function() { var original; 1..dec().assert_Is(0); (-1).dec().assert_Is(-2); 10..dec().assert_Is(9); 1..dec(0).assert_Is(1); 1..dec(4).assert_Is(-3); 10..dec(-1).assert_Is(11); 10..dec(-9).assert_Is(19); original = 1; return using(original, function() { this.dec().assert_Is(this - 1); this.assert_Is(1); this.dec(9).assert_Is(this - 9); return this.assert_Is(1); }); }); it('in_Between', function() { 10..in_Between(5, 15).assert_True(); 10..in_Between(-5, 15).assert_True(); 10..in_Between(10, 15).assert_False(); 10..in_Between(5, 10).assert_False(); 10..in_Between(11, 10).assert_False(); 10..in_Between(11, 20).assert_False(); return 10..in_Between(5, -5).assert_False(); }); it('inc', function() { var original; 1..inc().assert_Is(2); (-1).inc().assert_Is(0); 10..inc().assert_Is(11); 1..inc(0).assert_Is(1); 1..inc(4).assert_Is(5); 10..inc(-1).assert_Is(9); 10..inc(-9).assert_Is(1); original = 1; return using(original, function() { this.inc().assert_Is(this + 1); this.assert_Is(1); this.inc(9).assert_Is(this + 9); return this.assert_Is(1); }); }); it('is_Number', function() { 0..is_Number().assert_True(); (0/0).is_Number().assert_False(); return (function() { return 'a'.is_Number(); }).assert_Throws(function(error) { return error.message.assert_Is('"a\".is_Number is not a function'); }); }); it('invoke_After', function(done) { return 0..invoke_After(done); }); it('random', function() { 10..random().assert_In_Between(-1, 11); 100..random().assert_In_Between(-1, 101); 1000..random().assert_In_Between(-1, 1001); 10000..random().assert_In_Between(-1, 10001); 100..random(100).assert_In_Between(100, 201); return 1..random(100).assert_In_Between(99, 101); }); it('str', function() { 0..str.assert_Is_Function(); 0..str().assert_Is('0'); return 9..str().assert_Is('9'); }); return it('to_Decimal', function() { var a, b, c, d; a = 0.2; b = 0.4; c = a + b; c.assert_Is(0.6000000000000001); c.to_Decimal().assert_Is(0.6); c.to_Decimal().assert_Is(0.60); c.to_Decimal().assert_Is(0.6000000); c.to_Decimal().assert_Is(0.6000000000000000); c.to_Decimal().assert_Is_Not(0.6000000000000001); (typeof c.to_Decimal()).assert_Is('number'); (typeof c.to_Decimal().to_Decimal()).assert_Is('number'); c.to_Decimal().to_Decimal().assert_Is(0.6); d = c.to_Decimal(); (d + 0.3).assert_Is(0.8999999999999999); return (d + 0.3).to_Decimal().assert_Is(0.9); }); }); }).call(this);