Skip to content

Instantly share code, notes, and snippets.

@johnsonjo4531
Last active April 20, 2019 00:24
Show Gist options
  • Save johnsonjo4531/5f7ef8ce7c7420d67a0b6b43d979bd80 to your computer and use it in GitHub Desktop.
Save johnsonjo4531/5f7ef8ce7c7420d67a0b6b43d979bd80 to your computer and use it in GitHub Desktop.
Deno example of tests that should pass.
import { runTests, test } from "https://deno.land/std@v0.3.4/testing/mod.ts";
import {
assertNotEquals,
assertEquals,
equal
} from "https://deno.land/std@v0.3.4/testing/asserts.ts";
/**
* determines if the two sets are equal order shouldn't matter
*/
function equalsIncludingSet(setA, setB) {
if (setA instanceof Set || setB instanceof Set) {
if (!(setA instanceof Set && setB instanceof Set)) {
return false;
}
if (setA.size !== setB.size) {
return false;
}
for (const item of setA) {
if (!setB.has(item)) {
return false;
}
}
return true;
}
return equal(setA, setB);
}
function assertEqualsSet(setA, setB) {
if (!equalsIncludingSet(setA, setB)) {
throw new Error("SET A NOT EQUAL TO SET B");
}
}
function assertNotEqualsSet(setA, setB) {
if (equalsIncludingSet(setA, setB)) {
throw new Error("SET A IS EQUAL TO SET B");
}
}
test(function withNormalAssertions() {
const setA = new Set([1, 2, 3]);
const setB = new Set([1]);
const setC = new Set([3, 2, 1]);
assertEquals(setA, setC);
assertNotEquals(setA, setB);
});
test(function withModifiedAssertionsForSets() {
const setA = new Set([1, 2, 3]);
const setB = new Set([1]);
const setC = new Set([3, 2, 1]);
assertEqualsSet(setA, setC);
assertNotEqualsSet(setA, setB);
});
runTests();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment