Created
March 2, 2012 18:11
-
-
Save Gab-km/1960130 to your computer and use it in GitHub Desktop.
Tuples, immutable groups ... but my tuples are very poor :(
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
function write(message) { | |
document.getElementById("output").innerHTML += message + "<br />"; | |
} | |
function assertEquals(expected, actual) { | |
if (expected === actual) { | |
write("OK"); | |
} else { | |
var text = "expected = [" + expected.toString() | |
+ "], but actual = [" + actual.toString() + "]." | |
write("Failure: " + text); | |
} | |
} | |
function assertTrue(target) {assertEquals(true, target);} | |
function assertFalse(target) {assertEquals(false, target);} |
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
document.write('<script type="text/javascript" src="myJsUnit.js"></script>'); | |
function Tuple2(v1, v2) { | |
this._ = [v1, v2]; | |
} | |
Tuple2.prototype = { | |
getValue1 : function() { return this._[0]; }, | |
getValue2 : function() { return this._[1]; } | |
} | |
function Tuple3(v1, v2, v3) { | |
this._ = [v1, v2, v3]; | |
} | |
Tuple3.prototype = Tuple2.prototype; | |
Tuple3.prototype['getValue3'] = function() { return this._[2]; }; | |
function Tuple4(v1, v2, v3, v4) { | |
this._ = [v1, v2, v3, v4]; | |
} | |
Tuple4.prototype = Tuple3.prototype; | |
Tuple4.prototype['getValue4'] = function() { return this._[3]; }; | |
function testSuite() { | |
var tuple2 = new Tuple2(1, 2); | |
assertEquals(1, tuple2.getValue1()); | |
assertEquals(2, tuple2.getValue2()); | |
var tuple3 = new Tuple3(2, 3, 4); | |
assertEquals(2, tuple3.getValue1()); | |
assertEquals(3, tuple3.getValue2()); | |
assertEquals(4, tuple3.getValue3()); | |
var tuple4 = new Tuple4(1, 2, 3, 4); | |
assertEquals(1, tuple4.getValue1()); | |
assertEquals(2, tuple4.getValue2()); | |
assertEquals(3, tuple4.getValue3()); | |
assertEquals(4, tuple4.getValue4()); | |
} | |
window.onload = testSuite; |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Tuple test</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<script type="text/javascript" src="tuple.js"></script> | |
</head> | |
<body> | |
<div id="output" /> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment