Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit789516c

Browse files
committed
Dictionary 🏁
1 parent3441c6d commit789516c

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

‎examples/datastructures/dictionary.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
classDictionary{
2+
constructor(){
3+
this.dataStore=[];
4+
}
5+
6+
set(key,value){
7+
this.dataStore[key]=value;
8+
}
9+
10+
get(key){
11+
returnthis.dataStore[key];
12+
}
13+
14+
remove(key){
15+
deletethis.dataStore[key];
16+
}
17+
18+
showAll(){
19+
letstr="";
20+
for(letkeyofObject.keys(this.dataStore))
21+
str+=key+" -> "+this.dataStore[key]+"\n";
22+
returnstr;
23+
}
24+
25+
clear(){
26+
this.dataStore=[];
27+
}
28+
}
29+
30+
module.exports=Dictionary;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
constexpect=require('chai').expect;
2+
constDictionary=require('../../examples/datastructures/dictionary');
3+
4+
describe('=> DICTIONARY',function(){
5+
letnumbers;
6+
before(function(){
7+
numbers=newDictionary();
8+
});
9+
10+
it('should create an Empty Dictionary',function(done){
11+
expect(numbers.dataStore).to.deep.equal([]);
12+
done();
13+
});
14+
15+
it('should set a <key,value> pair in the Dictionary',function(done){
16+
numbers.set("Champu",3370123459);
17+
numbers.set("Zhampak",123991283);
18+
numbers.set("Raju",7118780921);
19+
expect(numbers.dataStore["Champu"]).to.equal(3370123459);
20+
expect(numbers.dataStore["Zhampak"]).to.equal(123991283);
21+
expect(numbers.dataStore["Raju"]).to.equal(7118780921);
22+
done();
23+
});
24+
25+
it('should get a value from the Dictionary',function(done){
26+
expect(numbers.get("Champu")).to.equal(3370123459);
27+
expect(numbers.get("Zhampak")).to.equal(123991283);
28+
expect(numbers.get("Raju")).to.equal(7118780921);
29+
done();
30+
});
31+
32+
it('should show all values from the Dictionary',function(done){
33+
expect(numbers.showAll()).to.equal("Champu -> 3370123459\nZhampak -> 123991283\nRaju -> 7118780921\n");
34+
done();
35+
});
36+
37+
it('should remove a value from the Dictionary',function(done){
38+
numbers.remove("Raju");
39+
expect(numbers.get("Raju")).to.equal(undefined);
40+
done();
41+
});
42+
43+
describe('=> clear',function(){
44+
it('should clear the Dictionary',function(done){
45+
numbers.clear();
46+
expect(numbers.dataStore).to.deep.equal([]);
47+
done();
48+
});
49+
});
50+
51+
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp