mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 07:46:16 -04:00
add tests for setOperations
This commit is contained in:
parent
7d15bfe58a
commit
20e54a8ecf
3 changed files with 309 additions and 4 deletions
|
@ -53,8 +53,8 @@ class SetOps {
|
|||
}
|
||||
|
||||
let result = {
|
||||
Union: this.runUnion,
|
||||
Intersection: this.runIntersect,
|
||||
"Union": this.runUnion,
|
||||
"Intersection": this.runIntersect,
|
||||
"Set Difference": this.runSetDifference,
|
||||
"Symmetric Difference": this.runSymmetricDifference,
|
||||
"Cartesian Product": this.runCartesianProduct,
|
||||
|
@ -62,7 +62,7 @@ class SetOps {
|
|||
}[operation]
|
||||
.apply(null, sets.map(s => s.split(itemDelimiter)));
|
||||
|
||||
// Formatting issues due to the nested characteristics of power set.
|
||||
// Formatting issues due to the nested characteristics of power set.
|
||||
if (operation === "Power Set") {
|
||||
result = result.map(i => `${i}\n`).join("");
|
||||
} else {
|
||||
|
@ -155,12 +155,18 @@ class SetOps {
|
|||
*/
|
||||
runPowerSet(delimiter) {
|
||||
return function(a) {
|
||||
|
||||
// empty array items getting picked up
|
||||
a = a.filter(i => i.length);
|
||||
if (!a.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} dec
|
||||
*/
|
||||
const toBinary = (dec) => (dec >>> 0).toString(2);
|
||||
|
||||
const result = new Set();
|
||||
const maxBinaryValue = parseInt(Number(a.map(i => "1").reduce((p, c) => p + c)), 2);
|
||||
const binaries = [...Array(maxBinaryValue + 1).keys()]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue