Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
* @danielromeo

# Only allow specific team to approve PRs to main
main @danielromeo
main @danielromeo

.github/workflows/* @danielromeo
2 changes: 1 addition & 1 deletion src/functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ describe('Jackscript class, Subset and Superset tests.', () => {
testSet5 = new JackscriptSet<string>("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);
})
Expand Down
25 changes: 17 additions & 8 deletions src/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,20 +170,29 @@ class JackscriptSet<T> implements Set<T> {
isReflexive(theSet: JackscriptSet<Coordinate<T, any>>) : Boolean {
let testCoordinate: Coordinate<T,T>;

// test variable:
let reflexiveTest = new JackscriptSet<Coordinate<number, number>>([[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;
}
Expand Down
32 changes: 23 additions & 9 deletions src/romeo.ts
Original file line number Diff line number Diff line change
@@ -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<T>(a: Coordinate<T, T>, b: Coordinate<T, T>): boolean {
return a[0] === b[0] && a[1] === b[1];
}
function setValuesEqual<T>(a: Set<T>, b: Set<T>): 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.
Expand All @@ -34,7 +29,6 @@ for(let item of myarray){
}

// console.log(nsetA.isReflexive(test));
let cod : Coordinate<number, number> = [1,1];


// testing the intersect method:
Expand Down Expand Up @@ -69,4 +63,24 @@ let reflexiveTest = new JackscriptSet<Coordinate<number, number>>([[1,1],[2,2],[
// console.log(reflexive.isReflexive(reflexiveTest));
// reflexive.isReflexive(reflexiveTest);

// console.log(reflexive.hasNew(reflexiveTest))
// console.log(reflexive.hasNew(reflexiveTest))

let cod : Coordinate<number, number> = [1,1];
let cod3 : Coordinate<number, number> = [1, 1];
let cod4 : Coordinate<number, number> = [3, 4];
let codfalse = [1,1];
// console.log(isCoordinate<number, number>(cod)); // returns true
// console.log(isCoordinate<string, number>(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();
40 changes: 40 additions & 0 deletions src/typechecker.test.ts
Original file line number Diff line number Diff line change
@@ -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<number, number>;
let coordinate2 : Coordinate<number, number>;
let coordinate3 : Coordinate<string, number>;
let coordinate4 : Coordinate<string, string>;
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);
})

});



25 changes: 25 additions & 0 deletions src/typechecker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {Coordinate} from "./coordinate"

// Function to check if value is a coordinate or not:
function isCoordinate<T, U>(value: any): value is Coordinate<T, U> {
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<T,V>(a: Coordinate<T,V>, b: Coordinate<T,V>): boolean{
if(!isCoordinate(a) || !isCoordinate(b)){
throw console.error("Parameters must be Coordinates.");
}
return a[0] === b[0] && a[1] === b[1];
}

function setValuesEqual<T>(a: Set<T>, b: Set<T>): boolean{
return a === b;
}

export {isCoordinate, coordinatesEqual};