Tests: bcmod version 44

Function:
Description: Get the modulus of the left_operand using modulus.
Version:
Status: current
Date: 2012-03-28 10:54
Summary: Fixing formatting.
Programmer: jj5
Tests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function bcmod_tests() {

  // API reference: http://docs.jquery.com/QUnit
  module( "bcmod" );

  test( "bcmod", function() {

    // some basic modulus cases:
    equal( bcmod( '4', '2' ), '0', "bcmod( '4', '2' )" );
    equal( bcmod( '2', '4' ), '2', "bcmod( '2', '4' )" );
    equal( bcmod( '123456', '1000' ), '456', "bcmod( '123456', '1000' )" );
    equal( bcmod( '12345', '1000' ), '345', "bcmod( '12345', '1000' )" );
    equal( bcmod( '1234', '1000' ), '234', "bcmod( '1234', '1000' )" );
    equal( bcmod( '123', '1000' ), '123', "bcmod( '123', '1000' )" );
    equal( bcmod( '12', '1000' ), '12', "bcmod( '12', '1000' )" );
    equal( bcmod( '1', '1000' ), '1', "bcmod( '1', '1000' )" );
    equal( bcmod( '123456', '100' ), '56', "bcmod( '123456', '100' )" );
    equal( bcmod( '12345', '100' ), '45', "bcmod( '12345', '100' )" );
    equal( bcmod( '1234', '100' ), '34', "bcmod( '1234', '100' )" );
    equal( bcmod( '123', '100' ), '23', "bcmod( '123', '100' )" );
    equal( bcmod( '12', '100' ), '12', "bcmod( '12', '100' )" );
    equal( bcmod( '1', '100' ), '1', "bcmod( '1', '100' )" );
    equal( bcmod( '123456', '10' ), '6', "bcmod( '123456', '10' )" );
    equal( bcmod( '12345', '10' ), '5', "bcmod( '12345', '10' )" );
    equal( bcmod( '1234', '10' ), '4', "bcmod( '1234', '10' )" );
    equal( bcmod( '123', '10' ), '3', "bcmod( '123', '10' )" );
    equal( bcmod( '12', '10' ), '2', "bcmod( '12', '10' )" );
    equal( bcmod( '1', '10' ), '1', "bcmod( '1', '10' )" );
    equal( bcmod( '123456', '1' ), '0', "bcmod( '123456', '1' )" );
    equal( bcmod( '12345', '1' ), '0', "bcmod( '12345', '1' )" );
    equal( bcmod( '1234', '1' ), '0', "bcmod( '1234', '1' )" );
    equal( bcmod( '123', '1' ), '0', "bcmod( '123', '1' )" );
    equal( bcmod( '12', '1' ), '0', "bcmod( '12', '1' )" );
    equal( bcmod( '1', '1' ), '0', "bcmod( '1', '1' )" );

    // fractional modulus is now supported:
    equal( bcmod( '10', '1.3' ), '0.9', "bcmod( '10', '1.3' )" );

    // testing negative left_operand:
    equal( bcmod( '-11', '2' ), '-1', "bcmod( '-11', '2' )" );

    // testing zero modulus and fractional modulus:
    equal( bcmod( '3', '0' ), null, "bcmod( '3', '0' )" );
    equal( bcmod( '3', '0.0' ), null, "bcmod( '3', '0.0' )" );
    bcmod_test( 3, 0.1, 0, 0.09999999999999984 );
    bcmod_test( 3, 0.11, 0.03, 0.029999999999999985 );
    bcmod_test( 3, 0.111, 0.003, 0.002999999999999961 );
    equal( bcmod( '3', '0.5' ), '0', "bcmod( '3', '0.5' )" );
    equal( bcmod( '3', '0.9' ), '0.3', "bcmod( '3', '0.9' )" );
    equal( bcmod( '3', '1' ), '0', "bcmod( '3', '1' )" );
    equal( bcmod( '3', '1.0' ), '0', "bcmod( '3', '1.0' )" );
    equal( bcmod( '3', '1.1' ), '0.8', "bcmod( '3', '1.1' )" );
    equal( bcmod( '3', '1.5' ), '0', "bcmod( '3', '1.5' )" );
    equal( bcmod( '3', '1.9' ), '1.1', "bcmod( '3', '1.9' )" );
    equal( bcmod( '3', '2' ), '1', "bcmod( '3', '2' )" );
    equal( bcmod( '3', '2.0' ), '1', "bcmod( '3', '2.0' )" );
    equal( bcmod( '3', '2.1' ), '0.9', "bcmod( '3', '2.1' )" );
    equal( bcmod( '3', '2.5' ), '0.5', "bcmod( '3', '2.5' )" );
    equal( bcmod( '3', '2.9' ), '0.1', "bcmod( '3', '2.9' )" );
    equal( bcmod( '3', '3' ), '0', "bcmod( '3', '3' )" );

    ok( true, "all pass" );

  } );

}

function bcmod_test( left_operand, modulus, expect, broken_js ) {
  if ( typeof broken_js === "undefined" ) { broken_js = expect; }
  equal( left_operand % modulus, broken_js, left_operand + " % " + modulus );
  equal(
    bcmod( left_operand.toString(), modulus.toString() ),
    expect.toString(),
    "bcmod( '" + left_operand + "', '" + modulus + "' )"
  );
}
[top]

Comments

There are no comments yet, be the first!

Please Login or Register to post comments.