test: add playground lab to practice

This commit is contained in:
yubintw
2025-03-18 23:24:32 +08:00
parent 692da86eae
commit a84687681d
3 changed files with 46 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
{ {
"cSpell.words": [ "cSpell.words": [
"fabonacci",
"fastify", "fastify",
"todos" "todos"
] ]

10
backend/src/utils/math.ts Normal file
View File

@@ -0,0 +1,10 @@
export function myCustomAdd(a: number, b: number): number {
return a + b
}
export function fabonacci(n: number): number {
if (n === 1 || n === 2) {
return 1
}
return fabonacci(n - 1) + fabonacci(n - 2)
}

View File

@@ -0,0 +1,35 @@
import { describe, test, expect, it } from 'vitest'
import { myCustomAdd, fabonacci } from '../src/utils/math'
import { fail } from 'assert'
describe('my testing playground', () => {
test('it works', () => {
const expected = true
const actual = false
expect(actual).toBe(expected)
})
describe('add function testing', () => {
it('should return 3 when add 1 and 2', () => {
expect(myCustomAdd(1, 2)).toBe(3)
})
it('should return 5 when add 2 and 3', () => {
// TODO: fix the test
fail('not implemented')
})
})
describe('fabonacci testing', () => {
it('should return 1 when n is 1', () => {
expect(fabonacci(1)).toBe(1)
})
it('should return 1 when n is 2', () => {
// TODO: fix the test
fail('not implemented')
})
it('should return 2 when n is 3', () => {
// TODO: fix the test
fail('not implemented')
})
})
})