From 3e6cec3efd03571d8447690e1b5456ef9139d31d Mon Sep 17 00:00:00 2001 From: danielromeo Date: Mon, 11 Nov 2024 15:24:48 +0200 Subject: [PATCH 1/6] unoffical testing: isCoordinate works --- src/functions.test.ts | 2 +- src/functions.ts | 25 +++++++++++++++++-------- src/romeo.ts | 25 ++++++++++++++++--------- src/typechecker.test.ts | 21 +++++++++++++++++++++ src/typechecker.ts | 25 +++++++++++++++++++++++++ 5 files changed, 80 insertions(+), 18 deletions(-) create mode 100644 src/typechecker.test.ts create mode 100644 src/typechecker.ts diff --git a/src/functions.test.ts b/src/functions.test.ts index 97b968d..be6a232 100644 --- a/src/functions.test.ts +++ b/src/functions.test.ts @@ -114,7 +114,7 @@ describe('Jackscript class, Subset and Superset tests.', () => { testSet5 = new JackscriptSet("sam"); }); - // isSubset method tests: + // isSubset() method tests: it('Does the function detect is isSubsetOf returns the correct boolean value.', ()=>{ expect(testSetDuplicate.isSubsetOf(testSet)).toBe(true); }) diff --git a/src/functions.ts b/src/functions.ts index 9b0e232..792b7db 100644 --- a/src/functions.ts +++ b/src/functions.ts @@ -170,20 +170,29 @@ class JackscriptSet implements Set { isReflexive(theSet: JackscriptSet>) : Boolean { let testCoordinate: Coordinate; + // test variable: + let reflexiveTest = new JackscriptSet>([[1,1],[2,2],[3,3]]); + + let it = theSet.internalSet.values(); var first = it.next(); for(let elem of this.internalSet){ + // console.log(elem); testCoordinate = [elem, elem]; + + console.log(typeof testCoordinate); + console.log(typeof reflexiveTest[0]); + + + // console.log(testCoordinate) - if(!theSet.has(testCoordinate)){ - console.log("i have found a mismatch"); - console.log("elem: ", testCoordinate, " and theSet.Internalset is : ", theSet.internalSet); - console.log("The type of the testCoordinate is : "+typeof testCoordinate+ " and the type of the internals set element is : "+ typeof first); - //console.log(testCoordinate === theSet.internalSet[0]) - - return false; - } + // if(!theSet.has(testCoordinate)){ + // console.log("i have found a mismatch"); + // console.log("elem: ", testCoordinate, " and theSet.Internalset is : ", theSet.internalSet); + // console.log("The type of the testCoordinate is : "+typeof testCoordinate+ " and the type of the internals set element is : "+ typeof first); + // return false; + // } } return true; } diff --git a/src/romeo.ts b/src/romeo.ts index 26b9a83..cdcbb5d 100644 --- a/src/romeo.ts +++ b/src/romeo.ts @@ -1,13 +1,8 @@ import {Coordinate, Relation} from './coordinate'; import {isValidSet, JackscriptSet} from './functions' +import {isCoordinate, coordinatesEqual} from './typechecker' + -// This function is to validate equality between two elements of the same type but not neccessarily coming from the same array... etc. -function coordinatesEqual(a: Coordinate, b: Coordinate): boolean { - return a[0] === b[0] && a[1] === b[1]; -} -function setValuesEqual(a: Set, b: Set): boolean{ - return a === b; -} // Make a mental note that a relation is not the same thing as a Jackscript set: // Keep them seperate... Dont try to run jackscriptset operations/methods on a realtion type. @@ -34,7 +29,6 @@ for(let item of myarray){ } // console.log(nsetA.isReflexive(test)); -let cod : Coordinate = [1,1]; // testing the intersect method: @@ -69,4 +63,17 @@ let reflexiveTest = new JackscriptSet>([[1,1],[2,2],[ // console.log(reflexive.isReflexive(reflexiveTest)); // reflexive.isReflexive(reflexiveTest); -// console.log(reflexive.hasNew(reflexiveTest)) \ No newline at end of file +// console.log(reflexive.hasNew(reflexiveTest)) + +let cod : Coordinate = [1,1]; +let cod3 : Coordinate = ["s", 4]; +let cod4 : Coordinate = [3, 4]; +let codfalse = [1,1]; +console.log("really ") +console.log(isCoordinate(cod)); // returns true +console.log(isCoordinate(cod3)) // returns +console.log(isCoordinate(codfalse)) // returns false + + + + diff --git a/src/typechecker.test.ts b/src/typechecker.test.ts new file mode 100644 index 0000000..9c30f98 --- /dev/null +++ b/src/typechecker.test.ts @@ -0,0 +1,21 @@ +import { JackscriptSet } from './functions'; +import { Coordinate, Relation } from './coordinate'; +import {isCoordinate, coordinatesEqual} from './typechecker' + +describe('Coordinates typechecker methods.', () => { + + let coordinate1 : Coordinate = [1,1]; + let coordinate2 : Coordinate = [2,2]; + + beforeEach(() => { + coordinate1 = [1,1]; + coordinate2 = [2,2]; + }); + + // test if variables are valide coordinates or not: + it('Value is a coordinate.', () => { + // expect(isCoordinate(coordinate1)).toBe(true); + }) + + +}); diff --git a/src/typechecker.ts b/src/typechecker.ts new file mode 100644 index 0000000..8102229 --- /dev/null +++ b/src/typechecker.ts @@ -0,0 +1,25 @@ +import {Coordinate} from "./coordinate" + +// Function to check if value is a coordinate or not: + function isCoordinate(value: any): value is Coordinate { + return ( + Array.isArray(value) && + value.length === 2 && + (typeof value[0] === typeof (undefined as T) || value[0] === value[0]) && + (typeof value[1] === typeof (undefined as U) || value[1] === value[1]) + ); + } + +// Function to check if two coordinates are equal or not: +function coordinatesEqual(a: Coordinate, b: Coordinate): boolean{ + if(!isCoordinate(a) || !isCoordinate(b)){ + throw console.error("Parameters must be Coordinates."); + } + return a[0] === b[0] && a[1] === b[1]; +} + +function setValuesEqual(a: Set, b: Set): boolean{ + return a === b; +} + +export {isCoordinate, coordinatesEqual}; \ No newline at end of file From 7f127cf0d5665384ec47ab79e1a356f8a4c229ee Mon Sep 17 00:00:00 2001 From: danielromeo Date: Mon, 11 Nov 2024 15:32:46 +0200 Subject: [PATCH 2/6] isCorrdinated does work when tested inside of a jackscript set. when iterating through a jackscript set of coordinates --- src/romeo.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/romeo.ts b/src/romeo.ts index cdcbb5d..6e3f5c6 100644 --- a/src/romeo.ts +++ b/src/romeo.ts @@ -66,14 +66,25 @@ let reflexiveTest = new JackscriptSet>([[1,1],[2,2],[ // console.log(reflexive.hasNew(reflexiveTest)) let cod : Coordinate = [1,1]; -let cod3 : Coordinate = ["s", 4]; +let cod3 : Coordinate = [1, 1]; let cod4 : Coordinate = [3, 4]; let codfalse = [1,1]; -console.log("really ") -console.log(isCoordinate(cod)); // returns true -console.log(isCoordinate(cod3)) // returns -console.log(isCoordinate(codfalse)) // returns false +// console.log(isCoordinate(cod)); // returns true +// console.log(isCoordinate(cod3)) // returns +//console.log(isCoordinate(codfalse)) // returns false +// testing corrdinates equal: + +// console.log(coordinatesEqual(cod, reflexiveTest[0])); +// console.log(reflexiveTest.entries().next()); + +const func = ()=>{ + reflexiveTest.forEach(element => { + console.log(isCoordinate(element)) + }); +} + +func(); From b96cb08ce9c22d660bb4829259ae95cd2aee50e2 Mon Sep 17 00:00:00 2001 From: danielromeo Date: Mon, 11 Nov 2024 15:35:55 +0200 Subject: [PATCH 3/6] coordinates equal successfully works --- src/romeo.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/romeo.ts b/src/romeo.ts index 6e3f5c6..71219f0 100644 --- a/src/romeo.ts +++ b/src/romeo.ts @@ -78,13 +78,10 @@ let codfalse = [1,1]; // console.log(coordinatesEqual(cod, reflexiveTest[0])); // console.log(reflexiveTest.entries().next()); -const func = ()=>{ +const func = () => { reflexiveTest.forEach(element => { - console.log(isCoordinate(element)) + console.log(coordinatesEqual(cod, element)) }); } func(); - - - From b5ddb0efafa25910c86e75bf49c4acaa9984e669 Mon Sep 17 00:00:00 2001 From: danielromeo Date: Mon, 11 Nov 2024 15:42:26 +0200 Subject: [PATCH 4/6] added tests for isCoordinate --- src/romeo.ts | 2 +- src/typechecker.test.ts | 27 +++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/romeo.ts b/src/romeo.ts index 71219f0..51826a5 100644 --- a/src/romeo.ts +++ b/src/romeo.ts @@ -80,7 +80,7 @@ let codfalse = [1,1]; const func = () => { reflexiveTest.forEach(element => { - console.log(coordinatesEqual(cod, element)) + // console.log(coordinatesEqual(cod, element)) }); } diff --git a/src/typechecker.test.ts b/src/typechecker.test.ts index 9c30f98..471cbfc 100644 --- a/src/typechecker.test.ts +++ b/src/typechecker.test.ts @@ -4,18 +4,37 @@ import {isCoordinate, coordinatesEqual} from './typechecker' describe('Coordinates typechecker methods.', () => { - let coordinate1 : Coordinate = [1,1]; - let coordinate2 : Coordinate = [2,2]; + let coordinate1 : Coordinate; + let coordinate2 : Coordinate; + let coordinate3 : Coordinate; + let coordinate4 : Coordinate; + let coordinate5fake = [1,1,2]; beforeEach(() => { coordinate1 = [1,1]; coordinate2 = [2,2]; + coordinate3 = ["a",1]; + coordinate4 = ["a", "b"]; }); // test if variables are valide coordinates or not: it('Value is a coordinate.', () => { - // expect(isCoordinate(coordinate1)).toBe(true); + expect(isCoordinate(coordinate1)).toBe(true); + }) + it('Value is a coordinate.', () => { + expect(isCoordinate(coordinate2)).toBe(true); + }) + it('Value is a coordinate.', () => { + expect(isCoordinate(coordinate3)).toBe(true); + }) + it('Value is a coordinate.', () => { + expect(isCoordinate(coordinate4)).toBe(true); + }) + it('Value is NOT a coordinate.', () => { + expect(isCoordinate(coordinate5fake)).toBe(false); }) - }); + + + From 09e5806ff3500d748a4d7f17ca90814c2b8f8fc6 Mon Sep 17 00:00:00 2001 From: danielromeo Date: Mon, 11 Nov 2024 15:51:09 +0200 Subject: [PATCH 5/6] added username to workflows --- .github/CODEOWNERS | 4 +++- src/romeo.ts | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index f1e34ce..76256dd 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -4,4 +4,6 @@ * @danielromeo # Only allow specific team to approve PRs to main -main @danielromeo \ No newline at end of file +main @danielromeo + +.github/workflows/* @danielromeo diff --git a/src/romeo.ts b/src/romeo.ts index 51826a5..149710c 100644 --- a/src/romeo.ts +++ b/src/romeo.ts @@ -78,10 +78,10 @@ let codfalse = [1,1]; // console.log(coordinatesEqual(cod, reflexiveTest[0])); // console.log(reflexiveTest.entries().next()); -const func = () => { - reflexiveTest.forEach(element => { - // console.log(coordinatesEqual(cod, element)) - }); -} +// const func = () => { +// reflexiveTest.forEach(element => { +// // console.log(coordinatesEqual(cod, element)) +// }); +// } -func(); +// func(); From b1002fa244593d8f9b382032770e7e7cf722689e Mon Sep 17 00:00:00 2001 From: danielromeo Date: Mon, 11 Nov 2024 16:01:45 +0200 Subject: [PATCH 6/6] test --- src/romeo.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/romeo.ts b/src/romeo.ts index 149710c..371fbcd 100644 --- a/src/romeo.ts +++ b/src/romeo.ts @@ -73,7 +73,6 @@ let codfalse = [1,1]; // console.log(isCoordinate(cod3)) // returns //console.log(isCoordinate(codfalse)) // returns false -// testing corrdinates equal: // console.log(coordinatesEqual(cod, reflexiveTest[0])); // console.log(reflexiveTest.entries().next());