2021-11-25 07:43:02 +00:00
|
|
|
/**
|
|
|
|
* @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]
|
|
|
|
*/
|
|
|
|
|
2022-01-25 19:43:17 +00:00
|
|
|
import { assert, expect } from "chai";
|
2021-11-25 07:43:02 +00:00
|
|
|
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");
|
|
|
|
});
|
2022-01-25 19:43:17 +00:00
|
|
|
it("flat-array", function () {
|
|
|
|
const m = new Map<string, string[]>();
|
|
|
|
m.set("a", ["a"]);
|
|
|
|
m.set("b", ["a","b"]);
|
|
|
|
const result = extractUniqueValues(m);
|
|
|
|
expect(result.size).to.equal(2)
|
|
|
|
assert.isTrue(
|
|
|
|
result.size === 2,
|
|
|
|
"The Element should include 2 elements. namely 'a' and 'b'"
|
|
|
|
);
|
|
|
|
assert.isArray([...result], "Should be an array");
|
|
|
|
expect([...result]).to.contain("a");
|
|
|
|
expect([...result]).to.contain("b");
|
|
|
|
});
|
2021-11-25 07:43:02 +00:00
|
|
|
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");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|