67 lines
2.0 KiB
TypeScript
67 lines
2.0 KiB
TypeScript
|
/**
|
||
|
* @author Martin Karkowski
|
||
|
* @email m.karkowski@zema.de
|
||
|
* @create date 2021-11-13 08:17:19
|
||
|
* @modify date 2021-11-13 09:44:51
|
||
|
* @desc [description]
|
||
|
*/
|
||
|
|
||
|
import { assert } from "chai";
|
||
|
import { describe, it } from "mocha";
|
||
|
import { extractUniqueValues } from "./mapMethods";
|
||
|
|
||
|
describe("mapMethods", function () {
|
||
|
// Describe the required Test:
|
||
|
|
||
|
describe("extractUniqueValues", function () {
|
||
|
it("simple-map", function () {
|
||
|
const m = new Map<string, string>();
|
||
|
m.set("a", "b");
|
||
|
m.set("b", "b");
|
||
|
|
||
|
const result = extractUniqueValues(m);
|
||
|
assert.isTrue(
|
||
|
result.size === 1,
|
||
|
"Elements have the same identity, but should be differend"
|
||
|
);
|
||
|
assert.isTrue([...result][0] === "b", "Element is element");
|
||
|
});
|
||
|
it("nested-map", function () {
|
||
|
const m = new Map<string, { a: string }>();
|
||
|
m.set("a", { a: "b" });
|
||
|
m.set("b", { a: "b" });
|
||
|
const result = extractUniqueValues(m, "a");
|
||
|
|
||
|
assert.isTrue(
|
||
|
result.size === 1,
|
||
|
"Elements have the same identity, but should be differend"
|
||
|
);
|
||
|
assert.isTrue([...result][0] === "b", "Element is element");
|
||
|
});
|
||
|
it("nested-array", function () {
|
||
|
const m = new Map<string, { a: string[] }>();
|
||
|
m.set("a", { a: ["b"] });
|
||
|
m.set("b", { a: ["b"] });
|
||
|
const result = extractUniqueValues(m, "a");
|
||
|
|
||
|
assert.isTrue(
|
||
|
result.size === 1,
|
||
|
"Elements have the same identity, but should be differend"
|
||
|
);
|
||
|
assert.isTrue([...result][0] === "b", "Element is element");
|
||
|
});
|
||
|
it("nested-array multiple elements", function () {
|
||
|
const m = new Map<string, { a: string[] }>();
|
||
|
m.set("a", { a: ["b"] });
|
||
|
m.set("b", { a: ["c", "d"] });
|
||
|
const result = extractUniqueValues(m, "a");
|
||
|
|
||
|
assert.isTrue(
|
||
|
result.size === 3,
|
||
|
"Elements have the same identity, but should be differend"
|
||
|
);
|
||
|
assert.deepEqual(["b", "c", "d"], [...result], "Items are missing");
|
||
|
});
|
||
|
});
|
||
|
});
|