Permalink
Browse files

Added 5 tests to show operators. Includes modulus

  • Loading branch information...
caleywoods committed Apr 12, 2011
1 parent 177984b commit e5d799689565370b6fa9854205afd9c34e66d857
Showing with 51 additions and 0 deletions.
  1. +1 −0 jskoans.htm
  2. +50 −0 topics/about_operators.js
View
@@ -7,6 +7,7 @@
<script type="text/javascript" src="support/qunit.js"></script>
<script type="text/javascript" src="support/koans.js"></script>
<script type="text/javascript" src="topics/about_asserts.js"></script>
+ <script type="text/javascript" src="topics/about_operators.js"></script>
<script type="text/javascript" src="topics/about_equality.js"></script>
<script type="text/javascript" src="topics/about_truthyness.js"></script>
<script type="text/javascript" src="topics/about_assignment.js"></script>
View
@@ -0,0 +1,50 @@
+$(document).ready(function(){
+
+ module("About Operators (topics/about_operators.js)");
+
+ test("addition", function() {
+ var result = 0;
+ //starting i at 0, add i to result and increment i by 1 until i is equal to 5
+ for (var i = 0; i <= 5; i++) {
+ result = result + i;
+ }
+ equals(result, __, "What is the value of result?");
+ });
+
+ test("assignment addition", function() {
+ var result = 0;
+ for (var i = 0; i <=5; i++) {
+ //the code below is just like saying result = result + i; but is more concise
+ result += i;
+ }
+ equals(result, __, "What is the value of result?");
+ });
+
+ test("subtraction", function() {
+ var result = 5;
+ for (var i = 0; i <= 2; i++) {
+ result = result - i;
+ }
+ equals(result, __, "What is the value of result?");
+ });
+
+ test("assignment subtraction", function() {
+ var result = 5;
+ for (var i = 0; i <= 2; i++) {
+ result -= i;
+ }
+ equals(result, __, "What is the value of result?");
+ });
+
+ //Assignment operators are available for multiplication and division as well
+ //let's do one more, the modulo operator, used for showing division remainder
+
+ test("modulus", function() {
+ var result = 10;
+ var x = 5;
+ //again this is exactly the same as result = result % x
+ result %= x;
+ equals(result, __, "What is the value of result?");
+ });
+
+});

0 comments on commit e5d7996

Please sign in to comment.