initial commit
This commit is contained in:
commit
4b60ece582
327 changed files with 28286 additions and 0 deletions
0
libjs/wTest/CMakeLists.txt
Normal file
0
libjs/wTest/CMakeLists.txt
Normal file
136
libjs/wTest/abstractlist.js
Normal file
136
libjs/wTest/abstractlist.js
Normal file
|
@ -0,0 +1,136 @@
|
|||
"use strict";
|
||||
var WTest = require("./test");
|
||||
var AbstractList = require("../wContainer/abstractlist");
|
||||
|
||||
var String = require("../wType/string");
|
||||
|
||||
var TAbsctractList = WTest.inherit({
|
||||
"className": "TAbsctractList",
|
||||
"constructor": function() {
|
||||
WTest.fn.constructor.call(this, "AbstractList");
|
||||
|
||||
var List = AbstractList.template(String);
|
||||
this._list = new List();
|
||||
|
||||
this._actions.push(this.testBeginEnd);
|
||||
this._actions.push(this.testSize);
|
||||
this._actions.push(this.testIterators);
|
||||
this._actions.push(this.testErasing);
|
||||
this._actions.push(this.testClear);
|
||||
this._actions.push(this.testInsertion);
|
||||
},
|
||||
"destructor": function() {
|
||||
this._list.destructor();
|
||||
|
||||
WTest.fn.destructor.call(this);
|
||||
},
|
||||
"testBeginEnd": function() {
|
||||
if (!this._list.begin()["=="](this._list.end())) {
|
||||
throw new Error("problem with empty list");
|
||||
}
|
||||
},
|
||||
"testSize": function() {
|
||||
this._list.push_back(new String("h"));
|
||||
|
||||
if (this._list.size() !== 1) {
|
||||
throw new Error("problem with size");
|
||||
}
|
||||
},
|
||||
"testInsertion": function() {
|
||||
var str1 = new String("one");
|
||||
this._list.insert(str1, this._list.end());
|
||||
|
||||
if (!this._list.begin()["*"]()["=="](str1)) {
|
||||
throw new Error("Problem with insertion to an empty list");
|
||||
}
|
||||
|
||||
var str2 = new String("two");
|
||||
this._list.insert(str2, this._list.begin());
|
||||
|
||||
if (!this._list.begin()["*"]()["=="](str2)) {
|
||||
throw new Error("Problem with insertion to the beginning of the list");
|
||||
}
|
||||
|
||||
var itr = this._list.begin();
|
||||
itr["++"]();
|
||||
var str3 = new String("oneAndAHalf");
|
||||
this._list.insert(str3, itr);
|
||||
|
||||
itr["--"]();
|
||||
if (!itr["*"]()["=="](str3)) {
|
||||
throw new Error("Problem with insertion to the middle of the list");
|
||||
}
|
||||
|
||||
var arr = [str2, str3, str1];
|
||||
var itr1 = this._list.begin();
|
||||
for (var i = 0; i < arr.length; ++i, itr1["++"]()) {
|
||||
if (!itr1["*"]()["=="](arr[i])) {
|
||||
throw new Error("Problem with the order of elements in list after insertion");
|
||||
}
|
||||
}
|
||||
},
|
||||
"testIterators": function() {
|
||||
var beg = this._list.begin();
|
||||
var end = this._list.end();
|
||||
|
||||
beg["++"]();
|
||||
end["--"]();
|
||||
|
||||
if (!beg["=="](this._list.end())) {
|
||||
throw new Error("problem with iterator incrementation");
|
||||
}
|
||||
if (!end["=="](this._list.begin())) {
|
||||
throw new Error("problem with iterator decrementation");
|
||||
}
|
||||
|
||||
this._list.pop_back();
|
||||
|
||||
if (!this._list.begin()["=="](this._list.end())) {
|
||||
throw new Error("problem with empty list");
|
||||
}
|
||||
},
|
||||
"testErasing": function() {
|
||||
this._list.push_back(new String("h"));
|
||||
this._list.push_back(new String("e"));
|
||||
this._list.push_back(new String("l"));
|
||||
this._list.push_back(new String("l"));
|
||||
this._list.push_back(new String("o"));
|
||||
this._list.push_back(new String(","));
|
||||
this._list.push_back(new String(" "));
|
||||
this._list.push_back(new String("w"));
|
||||
this._list.push_back(new String("w"));
|
||||
|
||||
var itr = this._list.end();
|
||||
itr["--"]();
|
||||
|
||||
this._list.push_back(new String("o"));
|
||||
this._list.push_back(new String("r"));
|
||||
this._list.push_back(new String("l"));
|
||||
this._list.push_back(new String("d"));
|
||||
this._list.push_back(new String("!"));
|
||||
|
||||
this._list.erase(itr);
|
||||
|
||||
var beg = this._list.begin();
|
||||
var end = this._list.end();
|
||||
|
||||
var str = new String();
|
||||
|
||||
for (; !beg["=="](end); beg["++"]()) {
|
||||
str["+="](beg["*"]());
|
||||
}
|
||||
|
||||
if (str.toString() !== "hello, world!") {
|
||||
throw new Error("Error push back and erasing");
|
||||
}
|
||||
},
|
||||
"testClear": function() {
|
||||
this._list.clear();
|
||||
|
||||
if (!this._list.begin()["=="](this._list.end())) {
|
||||
throw new Error("problem with empty list");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = TAbsctractList;
|
78
libjs/wTest/abstractmap.js
Normal file
78
libjs/wTest/abstractmap.js
Normal file
|
@ -0,0 +1,78 @@
|
|||
"use strict";
|
||||
var WTest = require("./test");
|
||||
var AbstractMap = require("../wContainer/abstractmap");
|
||||
|
||||
var String = require("../wType/string");
|
||||
var Address = require("../wType/address");
|
||||
|
||||
var TAbsctractMap = WTest.inherit({
|
||||
"className": "TAbsctractMap",
|
||||
"constructor": function() {
|
||||
WTest.fn.constructor.call(this, "AbstractMap");
|
||||
|
||||
var Map = AbstractMap.template(Address, String);
|
||||
this._map = new Map();
|
||||
|
||||
this._actions.push(this.testEnd);
|
||||
this._actions.push(this.testSize);
|
||||
this._actions.push(this.testIterators);
|
||||
this._actions.push(this.testClear);
|
||||
},
|
||||
"destructor": function() {
|
||||
this._map.destructor();
|
||||
|
||||
WTest.fn.destructor.call(this);
|
||||
},
|
||||
"testEnd": function() {
|
||||
var noEl = this._map.find(new Address(["addr1", "hop1"]));
|
||||
if (!noEl["=="](this._map.end())) {
|
||||
throw new Error("problem with end!");
|
||||
}
|
||||
},
|
||||
"testSize": function() {
|
||||
this._map.insert(new Address(["addr1", "hop1"]), new String("hello"));
|
||||
this._map.insert(new Address(["addr2", "hop2"]), new String("world"));
|
||||
this._map.insert(new Address(["addr2", "/hop2"]), new String("world2"));
|
||||
this._map.insert(new Address(["addr2", "/hop2", "hop4"]), new String("world3"));
|
||||
|
||||
if (this._map.size() !== 4) {
|
||||
throw new Error("problem with insertion!");
|
||||
}
|
||||
},
|
||||
"testIterators": function() {
|
||||
var itr = this._map.find(new Address(["addr1", "hop1"]));
|
||||
|
||||
if (itr["=="](this._map.end())) {
|
||||
throw new Error("problem with finding!");
|
||||
}
|
||||
|
||||
if (itr["*"]().second.toString() !== "hello") {
|
||||
throw new Error("wrong element found");
|
||||
}
|
||||
itr["++"]();
|
||||
if (itr["*"]().second.toString() !== "world2") {
|
||||
throw new Error("iterator dereferenced into wrong element after incrementetion");
|
||||
}
|
||||
|
||||
this._map.erase(itr);
|
||||
itr = this._map.find(new Address(["addr2", "/hop2"]));
|
||||
|
||||
if (!itr["=="](this._map.end())) {
|
||||
throw new Error("problem with erasing!");
|
||||
}
|
||||
|
||||
itr = this._map.find(new Address(["addr2", "/hop2", "hop4"]));
|
||||
if (itr["=="](this._map.end()) || itr["*"]().second.toString() !== "world3") {
|
||||
throw new Error("Something is wrong with finding");
|
||||
}
|
||||
},
|
||||
"testClear": function() {
|
||||
this._map.clear();
|
||||
|
||||
if (this._map.size() > 0) {
|
||||
throw new Error("problem with clearing!");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = TAbsctractMap;
|
93
libjs/wTest/abstractorder.js
Normal file
93
libjs/wTest/abstractorder.js
Normal file
|
@ -0,0 +1,93 @@
|
|||
"use strict";
|
||||
var WTest = require("./test");
|
||||
var AbstractOrder = require("../wContainer/abstractorder");
|
||||
var Address = require("../wType/address");
|
||||
|
||||
var TAbstractOrder = WTest.inherit({
|
||||
"className": "TAbstractOrder",
|
||||
"constructor": function() {
|
||||
WTest.fn.constructor.call(this, "AbstractOrder");
|
||||
|
||||
var Order = AbstractOrder.template(Address);
|
||||
this._order = new Order();
|
||||
|
||||
this._actions.push(this.testSize);
|
||||
this._actions.push(this.testIterators);
|
||||
this._actions.push(this.testEmpty);
|
||||
this._actions.push(this.testPushBackFind);
|
||||
},
|
||||
"destructor": function() {
|
||||
this._order.destructor();
|
||||
|
||||
WTest.fn.destructor.call(this);
|
||||
},
|
||||
"testSize": function() {
|
||||
var addr1 = new Address(["hop1", "hop2"]);
|
||||
this._order.push_back(addr1);
|
||||
|
||||
if (this._order.size() !== 1) {
|
||||
throw new Error("problem with size");
|
||||
}
|
||||
},
|
||||
"testIterators": function() {
|
||||
var addr1 = new Address(["hop1", "hop2"]);
|
||||
|
||||
var begin = this._order.begin();
|
||||
var itr = begin.clone();
|
||||
|
||||
if (!begin["*"]()["=="](addr1)) {
|
||||
throw new Error("problem with iterator");
|
||||
}
|
||||
|
||||
itr["++"]();
|
||||
if (!itr["=="](this._order.end())) {
|
||||
throw new Error("problem with iterator, end");
|
||||
}
|
||||
|
||||
if (!this._order.find(addr1)["=="](begin)) {
|
||||
throw new Error("problem with finding");
|
||||
}
|
||||
|
||||
this._order.erase(addr1);
|
||||
|
||||
if (addr1.toString() !== new Address(["hop1", "hop2"]).toString()) {
|
||||
throw new Error("key have been destroyed afrer eresing element");
|
||||
}
|
||||
},
|
||||
"testEmpty": function() {
|
||||
if (!this._order.begin()["=="](this._order.end())) {
|
||||
throw new Error("error: problem with empty order");
|
||||
}
|
||||
},
|
||||
"testPushBackFind": function() {
|
||||
this._order.push_back(new Address(["hop1", "hop2"]))
|
||||
this._order.push_back(new Address(["hop1", "hop3"]))
|
||||
this._order.push_back(new Address(["hop1", "hop4"]))
|
||||
this._order.push_back(new Address(["hop1", "hop5"]))
|
||||
this._order.push_back(new Address(["hop1", "hop6"]))
|
||||
this._order.push_back(new Address(["hop1", "hop7"]))
|
||||
|
||||
if (this._order.size() !== 6) {
|
||||
throw new Error("problem with size");
|
||||
}
|
||||
|
||||
var itr = this._order.find(new Address(["hop1", "hop4"]));
|
||||
var end = this._order.end();
|
||||
var arr = [
|
||||
new Address(["hop1", "hop4"]),
|
||||
new Address(["hop1", "hop5"]),
|
||||
new Address(["hop1", "hop6"]),
|
||||
new Address(["hop1", "hop7"])
|
||||
]
|
||||
var i = 0;
|
||||
|
||||
for (; !itr["=="](end); itr["++"]()) {
|
||||
if (!itr["*"]()["=="](arr[i])) {
|
||||
throw new Error("problem with finding element in the middle and iteration to the end");
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = TAbstractOrder;
|
29
libjs/wTest/test.js
Normal file
29
libjs/wTest/test.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
"use strict";
|
||||
|
||||
var Class = require("../utils/subscribable");
|
||||
|
||||
var Test = Class.inherit({
|
||||
"className": "Test",
|
||||
"constructor": function(name) {
|
||||
Class.fn.constructor.call(this);
|
||||
|
||||
this._name = name;
|
||||
this._actions = [];
|
||||
},
|
||||
"run": function() {
|
||||
this.trigger("start", this._name);
|
||||
var succsess = this._actions.length;
|
||||
for (var i = 0; i < this._actions.length; ++i) {
|
||||
this.trigger("progress", this._name, i + 1, this._actions.length);
|
||||
try {
|
||||
this._actions[i].call(this);
|
||||
} catch (e) {
|
||||
this.trigger("fail", this._name, i + 1, e);
|
||||
--succsess;
|
||||
}
|
||||
}
|
||||
this.trigger("end", this._name, succsess, this._actions.length);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = Test;
|
40
libjs/wTest/uint64.js
Normal file
40
libjs/wTest/uint64.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
"use strict";
|
||||
var WTest = require("./test");
|
||||
var Uint64 = require("../wType/uint64");
|
||||
|
||||
var TUint64 = WTest.inherit({
|
||||
"className": "TUint64",
|
||||
"constructor": function() {
|
||||
WTest.fn.constructor.call(this, "Uint64");
|
||||
|
||||
this._actions.push(this.testEq);
|
||||
this._actions.push(this.testGt);
|
||||
this._actions.push(this.testLt);
|
||||
},
|
||||
"testEq": function() {
|
||||
var first = new Uint64(5);
|
||||
var second = new Uint64(5);
|
||||
|
||||
if (!first["=="](second)) {
|
||||
throw new Error("problem with equals low");
|
||||
}
|
||||
},
|
||||
"testGt": function() {
|
||||
var first = new Uint64(5);
|
||||
var second = new Uint64(4);
|
||||
|
||||
if (!first[">"](second)) {
|
||||
throw new Error("problem with greater low");
|
||||
}
|
||||
},
|
||||
"testLt": function() {
|
||||
var first = new Uint64(4);
|
||||
var second = new Uint64(5);
|
||||
|
||||
if (!first["<"](second)) {
|
||||
throw new Error("problem with lower low");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = TUint64;
|
Loading…
Add table
Add a link
Reference in a new issue