-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: use Vitest's test.each for passing in multiple test cases
This also removes some extra trailing whitespace in various test files
- Loading branch information
1 parent
2bf662b
commit d40fa57
Showing
3 changed files
with
119 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,67 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import { getDifference, getIntersection, getSymmetricDifference, getUnion } from '../src'; | ||
import { | ||
getDifference, | ||
getIntersection, | ||
getSymmetricDifference, | ||
getUnion, | ||
} from '../src'; | ||
|
||
describe('getDifference', () => { | ||
test('difference of sets is computed correctly [1]', () => { | ||
test.each([ | ||
[[], [], []], | ||
[[1, 2, 3], [2, 3, 4], [1]], | ||
[[1, 2, 3, 4, 5, 6, 7, 8], [1, 2, 3, 4], [5, 6, 7, 8]], | ||
])('%O \\ %O = %O', (a, b, expected) => { | ||
expect(getDifference( | ||
new Set([1, 2, 3, 4, 5, 6, 7, 8]), | ||
new Set([1, 2, 3, 4]), | ||
)).toStrictEqual(new Set([5, 6, 7, 8])); | ||
}); | ||
|
||
|
||
test('difference of two sets is computed correctly [2]', () => { | ||
expect(getDifference( | ||
new Set<number>([1, 2, 3]), | ||
new Set<number>([2, 3, 4]), | ||
)).toStrictEqual( | ||
new Set<number>([1]), | ||
); | ||
new Set(a), | ||
new Set(b), | ||
)).toStrictEqual(new Set(expected)); | ||
}); | ||
}); | ||
|
||
describe('getIntersection', () => { | ||
test('intersection of two sets is computed correctly [1]', () => { | ||
expect(getIntersection<number>( | ||
new Set<number>([1, 2, 3]), | ||
new Set<number>([2, 3, 4]), | ||
)).toStrictEqual( | ||
new Set<number>([2, 3]), | ||
); | ||
}); | ||
|
||
test('intersection of two sets is computed correctly [2]', () => { | ||
expect(getIntersection( | ||
new Set([8, 9, 10, 11, 12, 13, 14, 15]), | ||
new Set([14, 15, 16, 17, 18, 19, 20]), | ||
)).toStrictEqual(new Set([14, 15])); | ||
}); | ||
|
||
|
||
test('intersection of two sets without any common elements returns an empty set', () => { | ||
test.each([ | ||
[[1, 2, 3], [4, 5, 6], []], | ||
[[1, 2, 3], [2, 3, 4], [2, 3]], | ||
[[8, 9, 10, 11, 12, 13, 14, 15], [14, 15, 16, 17, 18, 19, 20], [14, 15]], | ||
])('%O ∩ %O = %O', (a, b, expected) => { | ||
expect(getIntersection<number>( | ||
new Set<number>([1, 2, 3]), | ||
new Set<number>([4, 5, 6]), | ||
new Set<number>(a), | ||
new Set<number>(b), | ||
)).toStrictEqual( | ||
new Set<number>([]), | ||
new Set<number>(expected), | ||
); | ||
}); | ||
}); | ||
|
||
describe('getSymmetricDifference', () => { | ||
test('symmetric difference of two sets is computed correctly', () => { | ||
test.each([ | ||
[[], [], []], | ||
[[1, 2, 3], [1, 2, 3], []], | ||
[[1, 2, 3], [3, 4], [1, 2, 4]], | ||
[[1, 2, 3], [4, 5, 6], [1, 2, 3, 4, 5, 6]], | ||
])('%O △ %O = %O', (a, b, expected) => { | ||
expect(getSymmetricDifference( | ||
new Set<number>([1, 2, 3]), | ||
new Set<number>([3, 4]), | ||
new Set<number>(a), | ||
new Set<number>(b), | ||
)).toStrictEqual( | ||
new Set<number>([1, 2, 4]), | ||
new Set<number>(expected), | ||
); | ||
}); | ||
}); | ||
|
||
describe('getUnion', () => { | ||
test('union of two sets is computed correctly', () => { | ||
test.each([ | ||
[[], [], []], | ||
[[1, 2, 3], [2, 3, 4], [1, 2, 3, 4]], | ||
[[1, 2, 3, 4], [5, 6, 7, 8], [1, 2, 3, 4, 5, 6, 7, 8]], | ||
])('%O ∪ %O = %O', (a, b, expected) => { | ||
expect(getUnion<number>( | ||
new Set<number>([1, 2, 3, 4]), | ||
new Set<number>([5, 6, 7, 8]), | ||
new Set<number>(a), | ||
new Set<number>(b), | ||
)).toStrictEqual( | ||
new Set<number>([1, 2, 3, 4, 5, 6, 7, 8]), | ||
new Set<number>(expected), | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,103 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import { areSetsDisjoint, areSetsEqual, areSetsEquivalent, isProperSubsetOf, isProperSupersetOf, isSubsetOf, isSupersetOf } from '../src'; | ||
import { | ||
areSetsDisjoint, | ||
areSetsEqual, | ||
areSetsEquivalent, | ||
isProperSubsetOf, | ||
isProperSupersetOf, | ||
isSubsetOf, | ||
isSupersetOf, | ||
} from '../src'; | ||
|
||
describe('areSetsDisjoint', () => { | ||
test('two sets are disjoint to each other', () => { | ||
test.each([ | ||
[true, [], []], | ||
[true, [1, 2, 3], [4, 5, 6]], | ||
[false, [1, 2, 3], [3, 4, 5]], | ||
])('A ∩ B = ϕ is %O, (A = %O, B = %O)', (expected, a, b) => { | ||
expect(areSetsDisjoint( | ||
new Set<number>([1, 2, 3]), | ||
new Set<number>([4, 5, 6]), | ||
)).toBe(true); | ||
}); | ||
|
||
test('two sets are not disjoint to each other', () => { | ||
expect(areSetsDisjoint( | ||
new Set<number>([1, 2, 3]), | ||
new Set<number>([3, 4, 5]), | ||
)).toBe(false); | ||
new Set<number>(a), | ||
new Set<number>(b), | ||
)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('areSetsEqual', () => { | ||
test('two sets are equal to each other', () => { | ||
test.each([ | ||
[true, [], []], | ||
[true, [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]], | ||
])('A = B is %O, (A = %O, B = %O)', (expected, a, b) => { | ||
expect(areSetsEqual( | ||
new Set([1, 2, 3, 4, 5]), | ||
new Set([1, 2, 3, 4, 5]), | ||
)).toBe(true); | ||
}); | ||
|
||
test('two empty sets are equal to each other', () => { | ||
expect(areSetsEqual<number>( | ||
new Set<number>([]), | ||
new Set<number>([]), | ||
)).toBe(true); | ||
new Set(a), | ||
new Set(b), | ||
)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('areSetsEquivalent', () => { | ||
test('two empty sets are equivalent to each other', () => { | ||
expect(areSetsEquivalent<number>( | ||
new Set<number>(), | ||
new Set<number>(), | ||
)).toBe(true); | ||
}); | ||
|
||
test('two sets of same length are equivalent to each other', () => { | ||
test.each([ | ||
[true, [], []], | ||
[true, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]], | ||
[false, [1, 2, 3], []], | ||
])('|A| = |B| is %O, (A = %O, B = %O)', (expected, a, b) => { | ||
expect(areSetsEquivalent<number>( | ||
new Set<number>([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), | ||
new Set<number>([11, 12, 13, 14, 15, 16, 17, 18, 19, 20]), | ||
)).toBe(true); | ||
new Set<number>(a), | ||
new Set<number>(b), | ||
)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('isProperSubsetOf', () => { | ||
test('set A is correctly computed as a proper subset of set B', () => { | ||
test.each([ | ||
[true, [1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 6, 7, 8, 9]], | ||
[false, [1, 2, 3], [1, 2, 3]], | ||
[false, [], []], | ||
])('A ⊂ B is %O, (A = %O, B = %O)', () => { | ||
expect(isProperSubsetOf( | ||
new Set([1, 2, 3, 4, 5]), | ||
new Set([1, 2, 3, 4, 5, 6, 7, 8, 9]), | ||
)).toBe(true); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('isProperSupersetOf', () => { | ||
test('set A is correctly defined as a proper superset of set B', () => { | ||
test.each([ | ||
[true, [1, 2, 3, 4, 5, 6, 7, 8, 9], [1, 2, 3, 4, 5]], | ||
[false, [1, 2, 3], [1, 2, 3]], | ||
[false, [], []], | ||
])('A ⊃ B is %O, (A = %O, B = %O)', (expected, a, b) => { | ||
expect(isProperSupersetOf( | ||
new Set([1, 2, 3, 4, 5, 6, 7, 8, 9]), | ||
new Set([1, 2, 3, 4, 5]), | ||
)).toBe(true); | ||
}); | ||
new Set(a), | ||
new Set(b), | ||
)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('isSubsetOf', () => { | ||
test('set A is correctly defined as a subset of B', () => { | ||
test.each([ | ||
[true, [1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 9]], | ||
[false, [1, 2, 3, 4, 5, 9], [1, 2, 3, 4, 5]], | ||
[true, [1, 2, 3], [1, 2, 3]], | ||
[true, [], []], | ||
])('A ⊆ B is %O, (A = %O, B = %O)', (expected, a, b) => { | ||
expect(isSubsetOf( | ||
new Set([1, 2, 3, 4, 5]), | ||
new Set([1, 2, 3, 4, 5, 9]), | ||
)).toBe(true); | ||
}); | ||
new Set(a), | ||
new Set(b), | ||
)).toBe(expected); | ||
}); | ||
}); | ||
|
||
describe('isSupersetOf', () => { | ||
test('set A is a superset of set B', () => { | ||
test.each([ | ||
[true, [1, 2, 3, 4, 5, 7], [1, 3, 7]], | ||
[false, [1, 3, 7], [1, 2, 3, 4, 5, 7]], | ||
[true, [1, 3, 7], [1, 3, 7]], | ||
[true, [], []], | ||
])('A ⊇ B is %O, (A = %O, B = %O) ', (expected, a, b) => { | ||
expect(isSupersetOf( | ||
new Set([1, 2, 3, 4, 5, 7]), | ||
new Set([1, 3, 7]), | ||
)).toBe(true); | ||
}); | ||
new Set(a), | ||
new Set(b), | ||
)).toBe(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters