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/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..371fbcd 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,24 @@ 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 = [1, 1]; +let cod4 : Coordinate = [3, 4]; +let codfalse = [1,1]; +// console.log(isCoordinate(cod)); // returns true +// console.log(isCoordinate(cod3)) // returns +//console.log(isCoordinate(codfalse)) // returns false + + +// console.log(coordinatesEqual(cod, reflexiveTest[0])); +// console.log(reflexiveTest.entries().next()); + +// const func = () => { +// reflexiveTest.forEach(element => { +// // console.log(coordinatesEqual(cod, element)) +// }); +// } + +// func(); diff --git a/src/typechecker.test.ts b/src/typechecker.test.ts new file mode 100644 index 0000000..471cbfc --- /dev/null +++ b/src/typechecker.test.ts @@ -0,0 +1,40 @@ +import { JackscriptSet } from './functions'; +import { Coordinate, Relation } from './coordinate'; +import {isCoordinate, coordinatesEqual} from './typechecker' + +describe('Coordinates typechecker methods.', () => { + + 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); + }) + 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); + }) + +}); + + + 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