From a84687681dd01068e64aff952badcc52b9e68e3c Mon Sep 17 00:00:00 2001 From: yubintw Date: Tue, 18 Mar 2025 23:24:32 +0800 Subject: [PATCH] test: add playground lab to practice --- .vscode/settings.json | 1 + backend/src/utils/math.ts | 10 ++++++++++ backend/test/playground.test.ts | 35 +++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 backend/src/utils/math.ts create mode 100644 backend/test/playground.test.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index e33f2e3..394cd36 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "cSpell.words": [ + "fabonacci", "fastify", "todos" ] diff --git a/backend/src/utils/math.ts b/backend/src/utils/math.ts new file mode 100644 index 0000000..d326a6e --- /dev/null +++ b/backend/src/utils/math.ts @@ -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) +} diff --git a/backend/test/playground.test.ts b/backend/test/playground.test.ts new file mode 100644 index 0000000..cad2001 --- /dev/null +++ b/backend/test/playground.test.ts @@ -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') + }) + }) +})