Merging hackathon into hackathon
This commit is contained in:
@@ -14,6 +14,7 @@ export const UserScheduleStore = createLocalStore<IUserScheduleStore>({
|
||||
new UserSchedule({
|
||||
courses: [],
|
||||
name: 'Schedule 1',
|
||||
hours: 0,
|
||||
}),
|
||||
],
|
||||
activeIndex: 0,
|
||||
|
||||
@@ -6,7 +6,7 @@ export interface CourseColors {
|
||||
}
|
||||
|
||||
// calculates luminance of a hex string
|
||||
function getLuminance(hex: string): number {
|
||||
export function getLuminance(hex: string): number {
|
||||
let r = parseInt(hex.substring(1, 3), 16);
|
||||
let g = parseInt(hex.substring(3, 5), 16);
|
||||
let b = parseInt(hex.substring(5, 7), 16);
|
||||
|
||||
22
src/shared/util/tests/colors.test.ts
Normal file
22
src/shared/util/tests/colors.test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { getLuminance } from '../colors';
|
||||
|
||||
describe('getLuminance', () => {
|
||||
it('should return the correct luminance value for a given hex color', () => {
|
||||
// Test case 1: Hex color #FFFFFF (white)
|
||||
expect(getLuminance('#FFFFFF')).toBeCloseTo(1);
|
||||
|
||||
// Test case 2: Hex color #000000 (black)
|
||||
expect(getLuminance('#000000')).toBeCloseTo(0);
|
||||
|
||||
// Test case 3: Hex color #FF0000 (red)
|
||||
expect(getLuminance('#FF0000')).toBeCloseTo(0.2126);
|
||||
|
||||
// Test case 4: Hex color #00FF00 (green)
|
||||
expect(getLuminance('#00FF00')).toBeCloseTo(0.7152);
|
||||
|
||||
// Test case 5: Hex color #0000FF (blue)
|
||||
expect(getLuminance('#0000FF')).toBeCloseTo(0.0722);
|
||||
});
|
||||
});
|
||||
26
src/shared/util/tests/random.test.ts
Normal file
26
src/shared/util/tests/random.test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { generateRandomId } from '../random';
|
||||
|
||||
describe('generateRandomId', () => {
|
||||
it('should generate a random ID with the specified length', () => {
|
||||
// Test case 1: Length 5
|
||||
expect(generateRandomId(5)).toHaveLength(5);
|
||||
|
||||
// Test case 2: Length 10
|
||||
expect(generateRandomId(10)).toHaveLength(10);
|
||||
|
||||
// Test case 3: Length 15
|
||||
expect(generateRandomId(15)).toHaveLength(15);
|
||||
});
|
||||
|
||||
it('should generate a unique ID each time', () => {
|
||||
// Generate 100 IDs and check if they are all unique
|
||||
const ids = new Set<string>();
|
||||
for (let i = 0; i < 100; i += 1) {
|
||||
const id = generateRandomId();
|
||||
expect(ids.has(id)).toBe(false);
|
||||
ids.add(id);
|
||||
}
|
||||
});
|
||||
});
|
||||
39
src/shared/util/tests/string.test.ts
Normal file
39
src/shared/util/tests/string.test.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { capitalize } from '../string';
|
||||
|
||||
// TODO: Fix `string.ts` and `string.test.ts` to make the tests pass
|
||||
// `capitalize` is adding an extra space at the end of the word.
|
||||
describe('capitalize', () => {
|
||||
it('should capitalize the first letter of each word', () => {
|
||||
// Debug
|
||||
const word = 'hello world';
|
||||
const capitalized = capitalize(word);
|
||||
console.log(capitalize(word));
|
||||
console.log(capitalized.length);
|
||||
console.log(capitalized.split(''));
|
||||
|
||||
// Test case 1: Single word
|
||||
expect(capitalize('hello')).toBe('Hello');
|
||||
|
||||
// Test case 2: Multiple words
|
||||
expect(capitalize('hello world')).toBe('Hello World');
|
||||
|
||||
// Test case 3: Words with hyphens
|
||||
expect(capitalize('hello-world')).toBe('Hello-World');
|
||||
|
||||
// Test case 4: Words with hyphens and spaces
|
||||
expect(capitalize('hello-world test')).toBe('Hello-World Test');
|
||||
});
|
||||
|
||||
it('should not change the capitalization of the remaining letters', () => {
|
||||
// Test case 1: All lowercase
|
||||
expect(capitalize('hello')).toBe('Hello');
|
||||
|
||||
// Test case 2: All uppercase
|
||||
expect(capitalize('WORLD')).toBe('WORLD');
|
||||
|
||||
// Test case 3: Mixed case
|
||||
expect(capitalize('HeLLo WoRLd')).toBe('Hello World');
|
||||
});
|
||||
});
|
||||
14
src/shared/util/tests/time.test.ts
Normal file
14
src/shared/util/tests/time.test.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { sleep } from '../time';
|
||||
|
||||
describe('sleep', () => {
|
||||
it('should resolve after the specified number of milliseconds', async () => {
|
||||
const start = Date.now();
|
||||
const milliseconds = 1000;
|
||||
await sleep(milliseconds);
|
||||
const end = Date.now();
|
||||
const elapsed = end - start;
|
||||
expect(elapsed).toBeGreaterThanOrEqual(milliseconds);
|
||||
});
|
||||
});
|
||||
@@ -11,11 +11,26 @@ export const colors = {
|
||||
gray: '#9cadb7',
|
||||
offwhite: '#d6d2c4',
|
||||
concrete: '#95a5a6',
|
||||
red: '#B91C1C' // Not sure if this should be here, but it's used for remove course, and add course is ut-green
|
||||
},
|
||||
theme: {
|
||||
red: '#af2e2d',
|
||||
black: '#1a2024',
|
||||
},
|
||||
gradeDistribution: {
|
||||
a: '#22c55e',
|
||||
aminus: '#a3e635',
|
||||
bplus: '#84CC16',
|
||||
b: '#FDE047',
|
||||
bminus: '#FACC15',
|
||||
cplus: '#F59E0B',
|
||||
c: '#FB923C',
|
||||
cminus: '#F97316',
|
||||
dplus: '#EA580C', // TODO (achadaga): copilot generated, get actual color from Isaiah
|
||||
d: '#DC2626',
|
||||
dminus: '#B91C1C',
|
||||
f: '#B91C1C',
|
||||
},
|
||||
} as const;
|
||||
|
||||
type NestedKeys<T> = {
|
||||
|
||||
Reference in New Issue
Block a user