-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 독서기록 api 연동까지 수행 * feat: homepage 로딩처리 고도화, infinite쿼리 연동
- Loading branch information
Showing
20 changed files
with
690 additions
and
314 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { EXP_TABLE, calculateUserLevel, getGoalExp } from "./user.model"; | ||
|
||
describe("User.model를 테스트합니다.", () => { | ||
it("경험치가 1레벨 경험치보다 작으면 1레벨을 반환합니다.", () => { | ||
const exp = EXP_TABLE[1] - 1; | ||
const level = calculateUserLevel(exp); | ||
expect(level).toBe(1); | ||
}); | ||
it("경험치가 1레벨 경험치보다 크면 2레벨을 반환합니다.", () => { | ||
const exp = EXP_TABLE[1] + 1; | ||
const level = calculateUserLevel(exp); | ||
expect(level).toBe(2); | ||
}); | ||
it("경험치가 0이면 1레벨을 반환합니다.", () => { | ||
const exp = 0; | ||
const level = calculateUserLevel(exp); | ||
expect(level).toBe(1); | ||
}); | ||
it("경험치가 9레벨 수준이면 9레벨을 반환합니다.", () => { | ||
const exp = | ||
EXP_TABLE[1] + | ||
EXP_TABLE[2] + | ||
EXP_TABLE[3] + | ||
EXP_TABLE[4] + | ||
EXP_TABLE[5] + | ||
EXP_TABLE[6] + | ||
EXP_TABLE[7] + | ||
EXP_TABLE[8]; | ||
const level = calculateUserLevel(exp); | ||
expect(level).toBe(9); | ||
}); | ||
it("경험치가 9레벨 보다 높은 경우 10레벨을 반환합니다.", () => { | ||
const exp = | ||
EXP_TABLE[1] + | ||
EXP_TABLE[2] + | ||
EXP_TABLE[3] + | ||
EXP_TABLE[4] + | ||
EXP_TABLE[5] + | ||
EXP_TABLE[6] + | ||
EXP_TABLE[7] + | ||
EXP_TABLE[8] + | ||
EXP_TABLE[9]; | ||
const level = calculateUserLevel(exp); | ||
expect(level).toBe(10); | ||
}); | ||
}); | ||
|
||
describe("getGoalExp를 테스트합니다.", () => { | ||
it("1레벨 경험치 목표는 100입니다.", () => { | ||
const goalExp = getGoalExp(1); | ||
expect(goalExp).toBe(EXP_TABLE[1]); | ||
}); | ||
it("2레벨 경험치 목표는 200입니다.", () => { | ||
const goalExp = getGoalExp(2); | ||
expect(goalExp).toBe(EXP_TABLE[1] + EXP_TABLE[2]); | ||
}); | ||
it("3레벨 경험치 목표는 300입니다.", () => { | ||
const goalExp = getGoalExp(3); | ||
expect(goalExp).toBe(EXP_TABLE[1] + EXP_TABLE[2] + EXP_TABLE[3]); | ||
}); | ||
it("4레벨 경험치 목표는 500입니다.", () => { | ||
const goalExp = getGoalExp(4); | ||
expect(goalExp).toBe(EXP_TABLE[1] + EXP_TABLE[2] + EXP_TABLE[3] + EXP_TABLE[4]); | ||
}); | ||
it("5레벨 경험치 목표는 800입니다.", () => { | ||
const goalExp = getGoalExp(5); | ||
expect(goalExp).toBe(EXP_TABLE[1] + EXP_TABLE[2] + EXP_TABLE[3] + EXP_TABLE[4] + EXP_TABLE[5]); | ||
}); | ||
it("6레벨 경험치 목표는 1300입니다.", () => { | ||
const goalExp = getGoalExp(6); | ||
expect(goalExp).toBe( | ||
EXP_TABLE[1] + EXP_TABLE[2] + EXP_TABLE[3] + EXP_TABLE[4] + EXP_TABLE[5] + EXP_TABLE[6], | ||
); | ||
}); | ||
it("7레벨 경험치 목표는 2100입니다.", () => { | ||
const goalExp = getGoalExp(7); | ||
expect(goalExp).toBe( | ||
EXP_TABLE[1] + | ||
EXP_TABLE[2] + | ||
EXP_TABLE[3] + | ||
EXP_TABLE[4] + | ||
EXP_TABLE[5] + | ||
EXP_TABLE[6] + | ||
EXP_TABLE[7], | ||
); | ||
}); | ||
it("8레벨 경험치 목표는 3400입니다.", () => { | ||
const goalExp = getGoalExp(8); | ||
expect(goalExp).toBe( | ||
EXP_TABLE[1] + | ||
EXP_TABLE[2] + | ||
EXP_TABLE[3] + | ||
EXP_TABLE[4] + | ||
EXP_TABLE[5] + | ||
EXP_TABLE[6] + | ||
EXP_TABLE[7] + | ||
EXP_TABLE[8], | ||
); | ||
}); | ||
it("9레벨 경험치 목표는 5500입니다.", () => { | ||
const goalExp = getGoalExp(9); | ||
expect(goalExp).toBe( | ||
EXP_TABLE[1] + | ||
EXP_TABLE[2] + | ||
EXP_TABLE[3] + | ||
EXP_TABLE[4] + | ||
EXP_TABLE[5] + | ||
EXP_TABLE[6] + | ||
EXP_TABLE[7] + | ||
EXP_TABLE[8] + | ||
EXP_TABLE[9], | ||
); | ||
}); | ||
it("10레벨 경험치 목표는 9레벨과 동일합니다.", () => { | ||
const goalExp = getGoalExp(10); | ||
expect(goalExp).toBe( | ||
EXP_TABLE[1] + | ||
EXP_TABLE[2] + | ||
EXP_TABLE[3] + | ||
EXP_TABLE[4] + | ||
EXP_TABLE[5] + | ||
EXP_TABLE[6] + | ||
EXP_TABLE[7] + | ||
EXP_TABLE[8] + | ||
EXP_TABLE[9], | ||
); | ||
}); | ||
}); |
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,3 +1,46 @@ | ||
export interface User { | ||
exp: number; | ||
} | ||
|
||
export const EXP_TABLE = { | ||
1: 100, | ||
2: 100, | ||
3: 100, | ||
4: 200, | ||
5: 300, | ||
6: 500, | ||
7: 800, | ||
8: 1300, | ||
9: 2100, | ||
} as const; | ||
|
||
export const calculateUserLevel = (exp: number): number => { | ||
let accumulatedExp = 0; | ||
|
||
for (const [level, requiredExp] of Object.entries(EXP_TABLE)) { | ||
accumulatedExp += requiredExp; | ||
if (exp < accumulatedExp) { | ||
return Number(level); | ||
} | ||
} | ||
|
||
return Object.keys(EXP_TABLE).length + 1; | ||
}; | ||
|
||
export const getGoalExp = (level: number) => { | ||
let goalExp = 0; | ||
|
||
for (let i = 1; i <= level; i++) { | ||
goalExp += EXP_TABLE[i as keyof typeof EXP_TABLE] ?? 0; | ||
} | ||
|
||
return goalExp; | ||
}; | ||
|
||
export const getExpPercentage = (exp: number, goalExp: number): number => { | ||
const result = (exp / goalExp) * 100; | ||
if (Number.isNaN(result)) { | ||
return 1; | ||
} | ||
return result; | ||
}; |
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
69 changes: 0 additions & 69 deletions
69
src/features/bookRecordWrite/BookRecordWriteSearchStep.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.