Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
osofem authored Jun 12, 2017
1 parent 64e5354 commit 392861f
Show file tree
Hide file tree
Showing 16 changed files with 567 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Documentation/Test/BigArith - Initialization.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<html>
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting -->
<xscript src="https://cdn.rawgit.com/osofem/BigArith.js/v0.0-beta0.0/BigArith.js"></xscript>
<script src="../../BigArith.js"></script>
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript>
<script src="../../../assert/assert.js"></script>
<script>
/*Initializing a BigArith object*/
var ba = new BigArith(); //This initialises to "0"
assertDeepEqual(ba, new BigArith(0));

var ba = new BigArith(""); //With an empty string, this initialises to "0"
assertDeepEqual(ba, new BigArith(0));

ba = new BigArith(123); //via number
assertDeepEqual(ba, new BigArith("123"));

ba = new BigArith("0.5"); //via strings
assertDeepEqual(ba, new BigArith("0.5"));

ba = new BigArith("twenty five point three eight"); //via words
assertDeepEqual(ba, new BigArith("25.38"));

ba = new BigArith(5e3); //via number in expontial form
assertDeepEqual(ba, new BigArith("5000"));

ba = new BigArith("negative thirty four"); //negative words
assertDeepEqual(ba, new BigArith("-34"));

ba = new BigArith("positive sixty eight"); //positive words, though the "positive" is not necessary
assertDeepEqual(ba, new BigArith("68"));

ba = new BigArith("-34"); //negative strings
assertDeepEqual(ba, new BigArith("-34"));

ba = new BigArith("+34"); //positive strings, though the "+" is not necessary
assertDeepEqual(ba, new BigArith("34"));
</script>
</html>
72 changes: 72 additions & 0 deletions Documentation/Test/BigArith - add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<html>
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting -->
<xscript src="https://cdn.rawgit.com/osofem/BigArith.js/v0.0-beta0.0/BigArith.js"></xscript>
<script src="../../BigArith.js"></script>
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript>
<script src="../../../assert/assert.js"></script>
<script>
var result;

var x = new BigArith("0.5");
var y = new BigArith("zero point five");
var z = new BigArith(0.5);

var a = new BigArith(".5");
var b = new BigArith("point five");
var c = new BigArith(5e-1);

//You should be able to add words, strings or numbers to a BigArith object using the add() function
result = x.add("point five").add(.5).add(".5").add(5e-1);
assertDeepEqual(result, new BigArith(2.5)); // => "2.5" = 0.5 + 0.5 + 0.5 + 0.5 + 0.5

//You should be able to add BigArith objects together using the add() function
result = x.add(y).add(z);
assertDeepEqual(result, new BigArith(1.5)); // => "1.5" = 0.5 + 0.5 + 0.5

//You should be able to take a result and still add to it
result = result.add(2);
assertDeepEqual(result, new BigArith(3.5)); // => "3.5" = 1.5 + 2

/* The add() function always result a BigArith object
* Get the value of your result as a string using the valueOf() function*/
assertEqual(result.valueOf(), "3.5"); // => "3.5" = 1.5 + 2

//You should be able to add BigArith constants together
d = new BigArith("PI");
assertEqual(d.add(new BigArith("LN2")).valueOf(), "3.8347398341497383"); // => "3.8347398341497383" = PI + LN2

var i = new BigArith("-2");
assertEqual(i.add("-3").toWords(), "negative five");

//Further example
var ai = new BigArith("one point five");
var bi = new BigArith("123");
var ci = new BigArith(3);
result = ai.add(bi).add(ci);
assertEqual(result.valueOf(), "127.5"); // => "127.5" = 1.5 + 123 + 3

//You should be able to do this
d = new BigArith("-5");
result = d.add("-3");
assertEqual(result.valueOf(), "-8"); // => "-8" = -5 + -3

//And this
d = new BigArith("5");
result = d.add("negative three");
assertEqual(result.valueOf(), "2"); // => "2" = 5 + -3

//Get your answers in words
var hj = new BigArith("six hundred and three");
assertEqual(hj.add("ten").toWords(), "six hundred and thirteen");
assertEqual(hj.add("twenty").toWords(), "six hundred and twenty three");

var i = new BigArith("five hundred");
assertEqual(i.add("two hundred and seven").toWords(), "seven hundred and seven");

i = new BigArith("one thousand point eight");
assertEqual(i.add("three hundred and two").toWords(), "one thousand three hundred and two point eight");
assertEqual(i.add("one").toWords(), "one thousand one point eight");


</script>
</html>
28 changes: 28 additions & 0 deletions Documentation/Test/BigArith - ceil.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<html>
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting -->
<xscript src="https://cdn.rawgit.com/osofem/BigArith.js/v0.0-beta0.0/BigArith.js"></xscript>
<script src="../../BigArith.js"></script>
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript>
<script src="../../../assert/assert.js"></script>
<script>
var x = new BigArith("1.1");
var y = new BigArith("1.9");
var z = new BigArith(7.45);

var a = new BigArith(".05");
var b = new BigArith("eighty three point seven three");
var c = new BigArith("56857675753763473473463574574575693849335.567787856456453");

//Ceil
assertDeepEqual(x.ceil(), new BigArith(2));
assertDeepEqual(y.ceil(), new BigArith(2));
assertDeepEqual(z.ceil(), new BigArith(8));
assertDeepEqual(a.ceil(), new BigArith(1));
assertDeepEqual(b.ceil(), new BigArith(84));
assertDeepEqual(c.ceil(), new BigArith("56857675753763473473463574574575693849336"));

//Negative
assertDeepEqual(new BigArith("-45.23").ceil(), new BigArith("-45"));
assertDeepEqual(new BigArith("-75.99").ceil(), new BigArith("-75"));
</script>
</html>
23 changes: 23 additions & 0 deletions Documentation/Test/BigArith - compare.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<html>
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting -->
<xscript src="https://cdn.rawgit.com/osofem/BigArith.js/v0.0-beta0.0/BigArith.js"></xscript>
<script src="../../BigArith.js"></script>
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript>
<script src="../../../assert/assert.js"></script>
<script>
var x = new BigArith(2);

//Compare
assertEqual(x.compare("2"), "equal");
assertEqual(x.compare(-2), "greater");
assertEqual(x.compare("two"), "equal");
assertEqual(x.compare("two"), "equal");
assertEqual(x.compare("negative two"), "greater");
assertEqual(x.compare("-2"), "greater");

//Or
assertEqual(BigArith.compare("+165.8987","165.898700000000000000000"), "equal");
assertEqual(BigArith.compare("0.123568123","0.03455893"), "greater");
assertEqual(BigArith.compare("2","3"), "lesser");
</script>
</html>
23 changes: 23 additions & 0 deletions Documentation/Test/BigArith - compareAbs.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<html>
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting -->
<xscript src="https://cdn.rawgit.com/osofem/BigArith.js/v0.0-beta0.0/BigArith.js"></xscript>
<script src="../../BigArith.js"></script>
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript>
<script src="../../../assert/assert.js"></script>
<script>
var x = new BigArith(2);

//CompareAbs
assertEqual(x.compareAbs("2"), "equal");
assertEqual(x.compareAbs(-2), "equal");
assertEqual(x.compareAbs("two"), "equal");
assertEqual(x.compareAbs("2.0"), "equal");
assertEqual(x.compareAbs("negative two"), "equal");
assertEqual(x.compareAbs("-2"), "equal");

//Or
assertEqual(BigArith.compareAbs("-165.8987", "165.898700000000000000000"), "equal");
assertEqual(BigArith.compareAbs("0.123568123", "-0.03455893"), "greater");
assertEqual(BigArith.compareAbs("+0.03455893", "0.123568123"), "lesser");
</script>
</html>
69 changes: 69 additions & 0 deletions Documentation/Test/BigArith - divide.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<html>
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting -->
<xscript src="https://cdn.rawgit.com/osofem/BigArith.js/v0.0-beta0.0/BigArith.js"></xscript>
<script src="../../BigArith.js"></script>
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript>
<script src="../../../assert/assert.js"></script>
<script>
assertDeepEqual(BigArith.divide("426", 2), new BigArith(213));
assertDeepEqual(BigArith.divide("128", 2), new BigArith(64));
assertDeepEqual(BigArith.divide("138", 2), new BigArith(69));
assertDeepEqual(BigArith.divide("111369497863972", 2), new BigArith("55684748931986"));

assertDeepEqual(BigArith.divide("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999998", 2), new BigArith("4999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"));

assertDeepEqual(BigArith.divide("999", "9"), new BigArith("111"));

assertDeepEqual(BigArith.divide("999999999999999999999999999999999999999999999999999999999999999999999999999", "999"), new BigArith("1001001001001001001001001001001001001001001001001001001001001001001001001"));

assertDeepEqual(BigArith.divide("888", "888"), new BigArith("1"));
assertDeepEqual(BigArith.divide("20", "2"), new BigArith("10"));
assertDeepEqual(BigArith.divide("408", "2"), new BigArith("204"));
assertDeepEqual(BigArith.divide("4008", "2"), new BigArith("2004"));
assertDeepEqual(BigArith.divide("40080", "2"), new BigArith("20040"));
assertDeepEqual(BigArith.divide("300", "2"), new BigArith("150"));
assertDeepEqual(BigArith.divide("3000", "2"), new BigArith("1500"));

assertDeepEqual(BigArith.divide("2100", "2"), new BigArith("1050"));
assertDeepEqual(BigArith.divide("20100", "2"), new BigArith("10050"));
assertDeepEqual(BigArith.divide("2222", "22"), new BigArith("101"));
assertDeepEqual(BigArith.divide("2010002400", "2"), new BigArith("1005001200"));
assertDeepEqual(BigArith.divide("9000", "2"), new BigArith("4500"));

assertDeepEqual(BigArith.divide("-4", "2"), new BigArith("-2"));
assertDeepEqual(BigArith.divide("4", "-2"), new BigArith("-2"));
assertDeepEqual(BigArith.divide("-4", "-2"), new BigArith("2"));
assertDeepEqual(BigArith.divide("2222222222222222", "2"), new BigArith("1111111111111111"));
assertDeepEqual(BigArith.divide("600000", "300"), new BigArith("2000"));

//Those with reminders
assertDeepEqual(BigArith.divide("21", 2), new BigArith("10.5"));
assertDeepEqual(BigArith.divide("21", 5), new BigArith("4.2"));
assertDeepEqual(BigArith.divide("17", 4), new BigArith("4.25"));
assertDeepEqual(BigArith.divide("657654", "1000"), new BigArith("657.654"));

assertDeepEqual(BigArith.divide("89", "3"), new BigArith("29.66666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666667"));

assertDeepEqual(BigArith.divide("1", 3), new BigArith("0.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333"));

assertDeepEqual(BigArith.divide("4", "2"), new BigArith("2"));
assertDeepEqual(BigArith.divide("22", "7"), new BigArith("3.14285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714285714"));

assertDeepEqual(BigArith.divide("5", "708"), new BigArith("0.00706214689265536723163841807909604519774011299435028248587570621468926553672316384180790960451977401129943502824858757062146892655367231638418079096045197740112994350282485875706214689265536723163842"));

assertDeepEqual(BigArith.divide("0", "2"), new BigArith(0));
assertDeepEqual(BigArith.divide("0.5", "0.2"), new BigArith("2.5"));
assertDeepEqual(BigArith.divide("0.5", "0.0234"), new BigArith("21.367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521367521"));

assertDeepEqual(BigArith.divide("0.5", "234"), new BigArith("0.00213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675213675"));
assertDeepEqual(BigArith.divide("0.0000345", "12"), new BigArith("0.000002875"));
assertDeepEqual(BigArith.divide("3.45", "12"), new BigArith("0.2875"));
assertDeepEqual(BigArith.divide("345", "0.0000012"), new BigArith("287500000"));
assertDeepEqual(BigArith.divide("345", "1.2"), new BigArith("287.5"));
assertDeepEqual(BigArith.divide("0.5", "0.5"), new BigArith("1"));
assertDeepEqual(BigArith.divide("12.25", "0.765625"), new BigArith("16"));

//Throws Error
//assertThrow(BigArith.divide("2", "0"));
</script>
</html>
26 changes: 26 additions & 0 deletions Documentation/Test/BigArith - floor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<html>
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting -->
<xscript src="https://cdn.rawgit.com/osofem/BigArith.js/v0.0-beta0.0/BigArith.js"></xscript>
<script src="../../BigArith.js"></script>
<script src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></script>
<script>
var x = new BigArith("0.5");
var y = new BigArith("zero point three");
var z = new BigArith(7.45);

var a = new BigArith(".05");
var b = new BigArith("eighty three point seven three");
var c = new BigArith("56857675753763473473463574574575693849335.567787856456453");

assertDeepEqual(x.floor(), new BigArith(0));
assertDeepEqual(y.floor(), new BigArith(0));
assertDeepEqual(z.floor(), new BigArith(7));
assertDeepEqual(a.floor(), new BigArith(0));
assertDeepEqual(b.floor(), new BigArith(83));
assertDeepEqual(c.floor(), new BigArith("56857675753763473473463574574575693849335"));

//Negative
assertDeepEqual(new BigArith("-45.23").floor(), new BigArith("-46"));
assertDeepEqual(new BigArith("-57.99").floor(), new BigArith("-58"));
</script>
</html>
18 changes: 18 additions & 0 deletions Documentation/Test/BigArith - isEven.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<html>
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting -->
<xscript src="https://cdn.rawgit.com/osofem/BigArith.js/v0.0-beta0.0/BigArith.js"></xscript>
<script src="../../BigArith.js"></script>
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript>
<script src="../../../assert/assert.js"></script>
<script>
assertExpect(new BigArith(4).isEven(), true);
assertExpect(new BigArith(3).isEven(), false);
assertExpect(new BigArith(4.4).isEven(), false, "Should be false, decimals are not even");
assertExpect(new BigArith("9999999999999999999999999999999999999998655555555555555333333333333333333333338").isEven(), true);
assertExpect(new BigArith("999999999999999999999999999999999999999865555555555555533333333333333333333333999999").isEven(), false);

//Negative
assertExpect(new BigArith(-4).isEven(), true);
assertExpect(new BigArith(-3).isEven(), false);
</script>
</html>
18 changes: 18 additions & 0 deletions Documentation/Test/BigArith - isOdd.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<html>
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting -->
<xscript src="https://cdn.rawgit.com/osofem/BigArith.js/v0.0-beta0.0/BigArith.js"></xscript>
<script src="../../BigArith.js"></script>
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript>
<script src="../../../assert/assert.js"></script>
<script>
assertExpect(new BigArith(4).isOdd(), false);
assertExpect(new BigArith(3).isOdd(), true);
assertExpect(new BigArith(4.4).isOdd(), false, "Should be false, decimals are not even or odd");
assertExpect(new BigArith("9999999999999999999999999999999999999998655555555555555333333333333333333333338").isOdd(), false);
assertExpect(new BigArith("999999999999999999999999999999999999999865555555555555533333333333333333333333999999").isOdd(), true);

//Negative
assertExpect(new BigArith(-4).isOdd(), false);
assertExpect(new BigArith(-3).isOdd(), true);
</script>
</html>
37 changes: 37 additions & 0 deletions Documentation/Test/BigArith - modulus.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<html>
<!--Remember to change /v0.0-beta0.0/ to the version you are targeting -->
<xscript src="https://cdn.rawgit.com/osofem/BigArith.js/v0.0-beta0.0/BigArith.js"></xscript>
<script src="../../BigArith.js"></script>
<xscript src="https://cdn.rawgit.com/osofem/assert.js/v0.0-beta0.0/assert.js"></xscript>
<script src="../../../assert/assert.js"></script>
<script>
assertDeepEqual(BigArith.modulus("426", 2), new BigArith(0));
assertDeepEqual(BigArith.modulus("128",21), new BigArith(2));
assertDeepEqual(BigArith.modulus("138",2), new BigArith(0));
assertDeepEqual(BigArith.modulus("99999", "2"), new BigArith(1));
assertDeepEqual(BigArith.modulus("21", 2), new BigArith(1));
assertDeepEqual(BigArith.modulus("2100", 2), new BigArith(0));
assertDeepEqual(BigArith.modulus("0", "2"), new BigArith(0));

assertIsNaN(BigArith.modulus("2", "0"));

assertDeepEqual(BigArith.modulus("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999",2), new BigArith(1));

assertDeepEqual(BigArith.modulus("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999","99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"), new BigArith("9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999"));

assertDeepEqual(BigArith.modulus("-2","3"), new BigArith("-2"));
assertDeepEqual(BigArith.modulus("-4","2"), new BigArith("-0"));
assertDeepEqual(BigArith.modulus("-2","-3"), new BigArith("-2"));

var a = new BigArith("426");
assertDeepEqual(a.modulus("2"), new BigArith("0"));
assertDeepEqual(a.modulus("3"), new BigArith("0"));
assertDeepEqual(a.modulus("5"), new BigArith("1"));

var b = new BigArith("99999");
assertDeepEqual(b.modulus("2"), new BigArith("1"));
assertDeepEqual(BigArith.modulus("0.9","0.2"), new BigArith("0.1"));
assertDeepEqual(BigArith.modulus("-0.9","0.2"), new BigArith("-0.1"));
assertDeepEqual(BigArith.modulus("-0.0009","0.2"), new BigArith("-0.0009"));
</script>
</html>
Loading

0 comments on commit 392861f

Please sign in to comment.