Skip to content
Open
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
8 changes: 8 additions & 0 deletions src/checkTemp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* Checks if the temperature is within a safe range.
* @param temp - temperature in Celsius
* @returns true if safe (between 18°C and 30°C), false otherwise
*/
export function checkTemperature(temp: number): boolean {
return temp >= 18 && temp <= 30;
}
17 changes: 17 additions & 0 deletions src/test/checkTemp.tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { describe, it, expect } from 'vitest';
import { checkTemperature } from '../checkTemp';

describe('checkTemperature', () => {
it('returns true for temperatures within safe range', () => {
expect(checkTemperature(20)).toBe(true);
expect(checkTemperature(25)).toBe(true);
});

it('returns false for temperatures below safe range', () => {
expect(checkTemperature(10)).toBe(false);
});

it('returns false for temperatures above safe range', () => {
expect(checkTemperature(35)).toBe(false);
});
});