rubric item tests

This commit is contained in:
2024-08-21 14:55:36 -06:00
parent aa85f80a4c
commit 0d79299072
4 changed files with 107 additions and 0 deletions

View File

@@ -2,3 +2,9 @@ export interface RubricItem {
label: string;
points: number;
}
export const rubricItemIsExtraCredit = (item: RubricItem) => {
const extraCredit = '(extra credit)';
return item.label.toLowerCase().includes(extraCredit.toLowerCase());
}

View File

@@ -109,6 +109,7 @@ const parseRubricMarkdown = (rawMarkdown: string) => {
};
export const assignmentMarkdownParser = {
parseRubricMarkdown,
parseMarkdown(input: string): LocalAssignment {
const settingsString = input.split("---")[0];
const {

View File

@@ -0,0 +1,100 @@
import { describe, it, expect } from "vitest";
import {
RubricItem,
rubricItemIsExtraCredit,
} from "../../assignmnet/rubricItem";
import { assignmentMarkdownParser } from "../../assignmnet/utils/assignmentMarkdownParser";
describe("RubricMarkdownTests", () => {
it("can parse one item", () => {
const rawRubric = `
- 2pts: this is the task
`;
const rubric: RubricItem[] =
assignmentMarkdownParser.parseRubricMarkdown(rawRubric);
expect(rubric.length).toBe(1);
expect(rubricItemIsExtraCredit(rubric[0])).toBe(false);
expect(rubric[0].label).toBe("this is the task");
expect(rubric[0].points).toBe(2);
});
it("can parse multiple items", () => {
const rawRubric = `
- 2pts: this is the task
- 3pts: this is the other task
`;
const rubric: RubricItem[] =
assignmentMarkdownParser.parseRubricMarkdown(rawRubric);
expect(rubric.length).toBe(2);
expect(rubricItemIsExtraCredit(rubric[0])).toBe(false);
expect(rubric[1].label).toBe("this is the other task");
expect(rubric[1].points).toBe(3);
});
it("can parse single point", () => {
const rawRubric = `
- 1pt: this is the task
`;
const rubric: RubricItem[] =
assignmentMarkdownParser.parseRubricMarkdown(rawRubric);
expect(rubricItemIsExtraCredit(rubric[0])).toBe(false);
expect(rubric[0].label).toBe("this is the task");
expect(rubric[0].points).toBe(1);
});
it("can parse single extra credit (lower case)", () => {
const rawRubric = `
- 1pt: (extra credit) this is the task
`;
const rubric: RubricItem[] =
assignmentMarkdownParser.parseRubricMarkdown(rawRubric);
expect(rubricItemIsExtraCredit(rubric[0])).toBe(true);
expect(rubric[0].label).toBe("(extra credit) this is the task");
});
it("can parse single extra credit (upper case)", () => {
const rawRubric = `
- 1pt: (Extra Credit) this is the task
`;
const rubric: RubricItem[] =
assignmentMarkdownParser.parseRubricMarkdown(rawRubric);
expect(rubricItemIsExtraCredit(rubric[0])).toBe(true);
expect(rubric[0].label).toBe("(Extra Credit) this is the task");
});
it("can parse floating point numbers", () => {
const rawRubric = `
- 1.5pt: this is the task
`;
const rubric: RubricItem[] =
assignmentMarkdownParser.parseRubricMarkdown(rawRubric);
expect(rubric[0].points).toBe(1.5);
});
it("can parse negative numbers", () => {
const rawRubric = `
- -2pt: this is the task
`;
const rubric: RubricItem[] =
assignmentMarkdownParser.parseRubricMarkdown(rawRubric);
expect(rubric[0].points).toBe(-2);
});
it("can parse negative floating point numbers", () => {
const rawRubric = `
- -2895.00053pt: this is the task
`;
const rubric: RubricItem[] =
assignmentMarkdownParser.parseRubricMarkdown(rawRubric);
expect(rubric[0].points).toBe(-2895.00053);
});
});