-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the negation of each & fixed documentation
- Loading branch information
Avram Cosmin
committed
Feb 21, 2024
1 parent
a88b3e2
commit e08ff57
Showing
69 changed files
with
1,684 additions
and
321 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
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
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,33 +1,33 @@ | ||
import { ArrayOfGivenTypeClass } from './array-type-class'; | ||
import {ArrayOfGivenTypeClass, NotArrayOfGivenTypeClass} from './array-type-class'; | ||
|
||
describe('ArrayOfGivenTypeClass', () => { | ||
// Defining simple type classes | ||
class TypeClass1 {} | ||
class TypeClass2 {} | ||
// Defining simple type classes | ||
class TypeClass1 { | ||
} | ||
|
||
// valid test cases | ||
it('should return true if the argument is an array of instances of the expected type class', () => { | ||
const arg = [new TypeClass1(), new TypeClass1()]; | ||
const result = ArrayOfGivenTypeClass(arg, TypeClass1); | ||
expect(result).toBe(true); | ||
}); | ||
class TypeClass2 { | ||
} | ||
|
||
// invalid test cases | ||
it('should return false if the argument is not an array of instances of the expected type class', () => { | ||
const arg = [new TypeClass1(), new TypeClass2()]; | ||
const result = ArrayOfGivenTypeClass(arg, TypeClass1); | ||
expect(result).toBe(false); | ||
}); | ||
const testData: [unknown, new (...args: never[]) => any, boolean][] = [ | ||
[[new TypeClass1(), new TypeClass1()], TypeClass1, false], | ||
[[new TypeClass1(), new TypeClass2()], TypeClass1, true], | ||
[[], TypeClass1, true], | ||
['not an array', TypeClass1, true] | ||
]; | ||
|
||
it('should return false if the argument is empty array', () => { | ||
const arg: never[] = []; | ||
const result = ArrayOfGivenTypeClass(arg, TypeClass1); | ||
expect(result).toBe(false); | ||
}); | ||
describe('ArrayOfGivenTypeClass', () => { | ||
test.each(testData)( | ||
'NotArrayOfGivenTypeClass: Expecting array of %p to be %p', | ||
(inputValue: unknown, expectedTypeClass: new (...args: never[]) => any, expectedOutput: boolean) => { | ||
expect(ArrayOfGivenTypeClass(inputValue, expectedTypeClass)).toBe(!expectedOutput); | ||
} | ||
); | ||
}); | ||
|
||
it('should return false if the argument is not an array', () => { | ||
const arg = 'not an array'; | ||
const result = ArrayOfGivenTypeClass(arg, TypeClass1); | ||
expect(result).toBe(false); | ||
}); | ||
describe('NotArrayOfGivenTypeClass', () => { | ||
test.each(testData)( | ||
'NotArrayOfGivenTypeClass: Expecting array of %p to be %p', | ||
(inputValue: unknown, expectedTypeClass: new (...args: never[]) => any, expectedOutput: boolean) => { | ||
expect(NotArrayOfGivenTypeClass(inputValue, expectedTypeClass)).toBe(expectedOutput); | ||
} | ||
); | ||
}); |
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
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,21 +1,41 @@ | ||
import { ArrayOfGivenTypePrimitive } from './array-type-primitive'; | ||
import {ArrayOfGivenTypePrimitive, NotArrayOfGivenTypePrimitive} from './array-type-primitive'; | ||
|
||
describe('ArrayOfGivenTypePrimitive function', () => { | ||
it('should return true when all array elements match the given type', () => { | ||
const arr = [1, 2, 3]; | ||
const expectedTypeofValue = 'number'; | ||
expect(ArrayOfGivenTypePrimitive<number>(arr, expectedTypeofValue)).toBe(true); | ||
}); | ||
it('should return true when all array elements match the given type', () => { | ||
const arr = [1, 2, 3]; | ||
const expectedTypeofValue = 'number'; | ||
expect(ArrayOfGivenTypePrimitive<number>(arr, expectedTypeofValue)).toBe(true); | ||
}); | ||
|
||
it('should return false when not all array elements match the given type', () => { | ||
const arr = [1, 'a', 3]; | ||
const expectedTypeofValue = 'number'; | ||
expect(ArrayOfGivenTypePrimitive<number>(arr, expectedTypeofValue)).toBe(false); | ||
}); | ||
it('should return false when not all array elements match the given type', () => { | ||
const arr = [1, 'a', 3]; | ||
const expectedTypeofValue = 'number'; | ||
expect(ArrayOfGivenTypePrimitive<number>(arr, expectedTypeofValue)).toBe(false); | ||
}); | ||
|
||
it('should return false when input is not an array', () => { | ||
const arg = 'test'; | ||
const expectedTypeofValue = 'string'; | ||
expect(ArrayOfGivenTypePrimitive<string>(arg, expectedTypeofValue)).toBe(false); | ||
}); | ||
it('should return false when input is not an array', () => { | ||
const arg = 'test'; | ||
const expectedTypeofValue = 'string'; | ||
expect(ArrayOfGivenTypePrimitive<string>(arg, expectedTypeofValue)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('NotArrayOfGivenTypePrimitive function', () => { | ||
it('should return true when not all array elements match the given type', () => { | ||
const arr = [1, 'a', 3]; | ||
const expectedTypeofValue = 'number'; | ||
expect(NotArrayOfGivenTypePrimitive<number>(arr, expectedTypeofValue)).toBe(true); | ||
}); | ||
|
||
it('should return true when input is not an array', () => { | ||
const arg = 'test'; | ||
const expectedTypeofValue = 'string'; | ||
expect(NotArrayOfGivenTypePrimitive<string>(arg, expectedTypeofValue)).toBe(true); | ||
}); | ||
|
||
it('should return false when all array elements match the given type', () => { | ||
const arr = [1, 2, 3]; | ||
const expectedTypeofValue = 'number'; | ||
expect(NotArrayOfGivenTypePrimitive<number>(arr, expectedTypeofValue)).toBe(false); | ||
}); | ||
}); |
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
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,19 +1,28 @@ | ||
import { OfArrayType } from './array'; | ||
import {NotOfArrayType, OfArrayType} from './array'; | ||
|
||
const testData: [unknown, boolean][] = [ | ||
[[], true], | ||
[new Array(2), true], | ||
[Object.keys({}), true], | ||
[[].keys(), false], | ||
[true, false], | ||
[{}, false] | ||
[[], true], | ||
[new Array(2), true], | ||
[Object.keys({}), true], | ||
[[].keys(), false], | ||
[true, false], | ||
[{}, false] | ||
]; | ||
|
||
describe('OfTypeArray', () => { | ||
test.each(testData)( | ||
'OfTypeArray: Expecting %p to be %p', | ||
(inputValue: unknown, expectedOutput: boolean) => { | ||
expect(OfArrayType(inputValue)).toBe(expectedOutput); | ||
} | ||
); | ||
test.each(testData)( | ||
'OfTypeArray: Expecting %p to be %p', | ||
(inputValue: unknown, expectedOutput: boolean) => { | ||
expect(OfArrayType(inputValue)).toBe(expectedOutput); | ||
} | ||
); | ||
}); | ||
|
||
describe('NotOfArrayType', () => { | ||
test.each(testData)( | ||
'NotOfArrayType: Expecting %p to be %p', | ||
(inputValue: unknown, expectedOutput: boolean) => { | ||
expect(NotOfArrayType(inputValue)).toBe(!expectedOutput); | ||
} | ||
); | ||
}); |
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
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,21 +1,41 @@ | ||
import { OfBooleanTypeAsString } from './boolean-as-string'; | ||
import {NotOfBooleanTypeAsString, OfBooleanTypeAsString} from './boolean-as-string'; | ||
|
||
test('OfBooleanTypeAsString: Expecting true as a string to be true', () => { | ||
expect(OfBooleanTypeAsString('true')).toBe(true); | ||
expect(OfBooleanTypeAsString('true')).toBe(true); | ||
}); | ||
|
||
test('OfBooleanTypeAsString: Expecting false as a string to be true', () => { | ||
expect(OfBooleanTypeAsString('false')).toBe(true); | ||
expect(OfBooleanTypeAsString('false')).toBe(true); | ||
}); | ||
|
||
test('OfBooleanTypeAsString: Expecting xyz string to be false', () => { | ||
expect(OfBooleanTypeAsString('xyz')).toBe(false); | ||
expect(OfBooleanTypeAsString('xyz')).toBe(false); | ||
}); | ||
|
||
test('OfBooleanTypeAsString: Expecting true to be false', () => { | ||
expect(OfBooleanTypeAsString(true)).toBe(false); | ||
expect(OfBooleanTypeAsString(true)).toBe(false); | ||
}); | ||
|
||
test('OfBooleanTypeAsString: Expecting {} to be false', () => { | ||
expect(OfBooleanTypeAsString({})).toBe(false); | ||
expect(OfBooleanTypeAsString({})).toBe(false); | ||
}); | ||
|
||
test('NotOfBooleanTypeAsString: Expecting true as a string to be false', () => { | ||
expect(NotOfBooleanTypeAsString('true')).toBe(false); | ||
}); | ||
|
||
test('NotOfBooleanTypeAsString: Expecting false as a string to be false', () => { | ||
expect(NotOfBooleanTypeAsString('false')).toBe(false); | ||
}); | ||
|
||
test('NotOfBooleanTypeAsString: Expecting xyz string to be true', () => { | ||
expect(NotOfBooleanTypeAsString('xyz')).toBe(true); | ||
}); | ||
|
||
test('NotOfBooleanTypeAsString: Expecting true to be true', () => { | ||
expect(NotOfBooleanTypeAsString(true)).toBe(true); | ||
}); | ||
|
||
test('NotOfBooleanTypeAsString: Expecting {} to be true', () => { | ||
expect(NotOfBooleanTypeAsString({})).toBe(true); | ||
}); |
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
Oops, something went wrong.