Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit

  • Loading branch information...
commit 5bde0dedc3775fb12901049b0c9d5863a1dc8730 1 parent 3fc67e2
Jonathan 'Wolf' Rentzsch authored
Showing with 131 additions and 80 deletions.
  1. +118 −0 flit.js
  2. +0 −80 index.html
  3. +13 −0 qunit.html
118 flit.js
View
@@ -0,0 +1,118 @@
+$(document).ready(function(){
+ test('recursive dictionary: empty',function(){
+ var d = new JRMutableDictionary();
+
+ equals(0, d.count(), 'empty dictionary count is 0');
+ equals(undefined, d.get('key1'), "get nonexistent slot's value");
+ equals(false, d.hasKey('key1'), "ensure dictionary doesn't have an uninserted slot");
+ });
+ test('recursive dictionary: one slot',function(){
+ var d = new JRMutableDictionary();
+
+ d.put('key1', 'value1');
+ equals(1, d.count(), 'dictionary count of 1');
+ equals('value1', d.get('key1'));
+ equals(undefined, d.get('key2'));
+ equals(true, d.hasKey('key1'), "ensure dictionary has inserted slot");
+ equals(false, d.hasKey('key2'), "ensure dictionary doesn't have uninserted slot");
+
+ d.remove('key1');
+ equals(0, d.count());
+ equals(undefined, d.get('key1'));
+ equals(undefined, d.get('key2'));
+ equals(false, d.hasKey('key1'), "ensure dictionary doesn't have removed slot");
+ equals(false, d.hasKey('key2'), "ensure dictionary doesn't have uninserted slot");
+ });
+ test('recursive dictionary: replace value',function(){
+ var d = new JRMutableDictionary();
+
+ d.put('key1', 'value1');
+ equals(1, d.count(), 'dictionary count of 1');
+ equals('value1', d.get('key1'));
+ equals(undefined, d.get('key2'));
+ equals(true, d.hasKey('key1'), "ensure dictionary has inserted slot");
+ equals(false, d.hasKey('key2'), "ensure dictionary doesn't have uninserted slot");
+
+ d.put('key1', 'value2');
+ equals(1, d.count(), 'dictionary count of 1');
+ equals('value2', d.get('key1'));
+ equals(undefined, d.get('key2'));
+ equals(true, d.hasKey('key1'), "ensure dictionary has inserted slot");
+ equals(false, d.hasKey('key2'), "ensure dictionary doesn't have uninserted slot");
+ });
+ test('recursive dictionary: two slots',function(){
+ var d = new JRMutableDictionary();
+
+ d.put('key1', 'value1');
+ d.put('key2', 'value2');
+ equals(2, d.count(), 'dictionary count of 2');
+ equals('value1', d.get('key1'));
+ equals('value2', d.get('key2'));
+ equals(undefined, d.get('key3'));
+ equals(true, d.hasKey('key1'), "ensure dictionary has inserted slot");
+ equals(true, d.hasKey('key2'), "ensure dictionary has inserted slot");
+ equals(false, d.hasKey('key3'), "ensure dictionary doesn't have uninserted slot");
+
+ d.remove('key1');
+ equals(1, d.count());
+ equals(undefined, d.get('key1'));
+ equals('value2', d.get('key2'));
+ equals(undefined, d.get('key3'));
+ equals(false, d.hasKey('key1'), "ensure dictionary doesn't have removed slot");
+ equals(true, d.hasKey('key2'), "ensure dictionary has inserted slot");
+ equals(false, d.hasKey('key3'), "ensure dictionary doesn't have uninserted slot");
+
+ d.remove('key2');
+ equals(0, d.count());
+ equals(undefined, d.get('key1'));
+ equals(undefined, d.get('key2'));
+ equals(undefined, d.get('key3'));
+ equals(false, d.hasKey('key1'), "ensure dictionary doesn't have removed slot");
+ equals(false, d.hasKey('key2'), "ensure dictionary doesn't have removed slot");
+ equals(false, d.hasKey('key3'), "ensure dictionary doesn't have uninserted slot");
+ });
+ test('recursive dictionary: put undefined',function(){
+ var d = new JRMutableDictionary();
+
+ d.put('key1', undefined);
+ equals(1, d.count(), 'undefined value still takes a slot');
+
+ equals(undefined, d.get('key1'), 'get slot with undefined value');
+
+ d.remove('key1');
+ equals(0, d.count(), 'can remove slot with undefined value');
+ });
+});
+
+function JRMutableDictionary() {
+ this._storage = {};
+ this._count = 0;
+}
+JRMutableDictionary.prototype.count = function(){
+ var key;
+
+ if (this._count === undefined) {
+ this._count = 0;
+ for (key in this._storage) {
+ this._count++;
+ }
+ }
+ return this._count;
+}
+JRMutableDictionary.prototype.get = function(key){
+ return this._storage[key];
+}
+JRMutableDictionary.prototype.put = function(key, value){
+ this._count = undefined;
+ this._storage[key] = value;
+}
+JRMutableDictionary.prototype.remove = function(key){
+ this._count = undefined;
+ delete this._storage[key];
+}
+JRMutableDictionary.prototype.hasKey = function(key){
+ return this._storage.hasOwnProperty(key);
+}
+
+// commits
+
80 index.html
View
@@ -1,80 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
-<head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-
- <title>rentzsch/flit @ GitHub</title>
-
- <style type="text/css">
- body {
- margin-top: 1.0em;
- background-color: #ffffff;
- font-family: "Helvetica,Arial,FreeSans";
- color: #000000;
- }
- #container {
- margin: 0 auto;
- width: 700px;
- }
- h1 { font-size: 3.8em; color: #000000; margin-bottom: 3px; }
- h1 .small { font-size: 0.4em; }
- h1 a { text-decoration: none }
- h2 { font-size: 1.5em; color: #000000; }
- h3 { text-align: center; color: #000000; }
- a { color: #000000; }
- .description { font-size: 1.2em; margin-bottom: 30px; margin-top: 30px; font-style: italic;}
- .download { float: right; }
- pre { background: #000; color: #fff; padding: 15px;}
- hr { border: 0; width: 80%; border-bottom: 1px solid #aaa}
- .footer { text-align:center; padding-top:30px; font-style: italic; }
- </style>
-
-</head>
-
-<body>
- <a href="http://github.com/rentzsch/flit"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub" /></a>
-
- <div id="container">
-
- <div class="download">
- <a href="http://github.com/rentzsch/flit/zipball/master">
- <img border="0" width="90" src="http://github.com/images/modules/download/zip.png"></a>
- <a href="http://github.com/rentzsch/flit/tarball/master">
- <img border="0" width="90" src="http://github.com/images/modules/download/tar.png"></a>
- </div>
-
- <h1><a href="http://github.com/rentzsch/flit">flit</a>
- <span class="small">by <a href="http://github.com/rentzsch">rentzsch</a></span></h1>
-
- <div class="description">
-
- </div>
-
- <h2>Authors</h2>
-<p>rentzsch (jwr.git@redshed.net)
-<br/>
-<br/> </p>
-<h2>Contact</h2>
-<p>Jonathan 'Wolf' Rentzsch (jwr.git@redshed.net)
-<br/> </p>
-
-
- <h2>Download</h2>
- <p>
- You can download this project in either
- <a href="http://github.com/rentzsch/flit/zipball/master">zip</a> or
- <a href="http://github.com/rentzsch/flit/tarball/master">tar</a> formats.
- </p>
- <p>You can also clone the project with <a href="http://git-scm.com">Git</a>
- by running:
- <pre>$ git clone git://github.com/rentzsch/flit</pre>
- </p>
-
- <div class="footer">
- get the source code on GitHub : <a href="http://github.com/rentzsch/flit">rentzsch/flit</a>
- </div>
-
- </div>
-
13 qunit.html
View
@@ -0,0 +1,13 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html>
+<head>
+ <title>flit</title>
+ <link rel="stylesheet" type="text/css" href="http://cloud.github.com/downloads/rentzsch/qunit/testsuite.css">
+ <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
+ <script type="text/javascript" src="http://cloud.github.com/downloads/rentzsch/qunit/testrunner.js"></script>
+ <script type="text/javascript" src="flit.js"></script>
+</head>
+<body>
+ <div id="main"></div>
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.