Skip to content

Commit

Permalink
fix: object-exam
Browse files Browse the repository at this point in the history
  • Loading branch information
luizchaves committed Mar 25, 2024
1 parent cdd1ef1 commit 66154ea
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/pages/exercises/object-exam/_assets/object-exams.pu
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ skinparam classAttributeIconSize 0
skinparam monochrome true
hide circle

class Exams {
class Exam {
-weight: Weight
-answer: Answer
-exams: Exam
-exams: Array<Answer>
+__construct(answer: Answer, weight: Weight)
+add(exam: Exam): void
+add(exam: Answer): void
+avg(): float
+min([count: float]): Array<float>
+max([count: float]): Array<float>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/exercises/object-exam/_assets/object-exams.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions src/pages/exercises/object-exam/_codes/js/code/exam.print.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import { Exam } from './exam.js';
// Exam Tool

const weight = { q1: 2, q2: 2, q3: 2, q4: 2, q5: 2 };
const answer = { q1: 'a', q2: 'b', q3: 'a', q4: 'c', q5: 'd' };

const answer = {
person: 'Professor',
values: { q1: 'a', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
};

const exam = new Exam(answer, weight);

exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

console.log(exam.avg());
Expand All @@ -28,7 +33,7 @@ console.log([]);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

console.log(exam.avg());
Expand Down
29 changes: 16 additions & 13 deletions src/pages/exercises/object-exam/_codes/js/code/exam.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ describe('Exam Tool', () => {
beforeEach(() => {
const weight = { q1: 2, q2: 2, q3: 2, q4: 2, q5: 2 };

const answer = { q1: 'a', q2: 'b', q3: 'a', q4: 'c', q5: 'd' };
const answer = {
person: 'Professor',
values: { q1: 'a', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
};

exam = new Exam(answer, weight);
});

it('should calculate average', () => {
exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

assert.equal(exam.avg(), 4);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

assert.equal(exam.avg(), 6);
Expand All @@ -32,14 +35,14 @@ describe('Exam Tool', () => {
it('should calculate minimum value', () => {
exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

assert.deepEqual(exam.min(), [4]);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

assert.deepEqual(exam.min(), [4]);
Expand All @@ -48,14 +51,14 @@ describe('Exam Tool', () => {
it('should calculate minimum value', () => {
exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

assert.deepEqual(exam.min(), [4]);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

assert.deepEqual(exam.min(), [4]);
Expand All @@ -64,14 +67,14 @@ describe('Exam Tool', () => {
it('should calculate maximum value', () => {
exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

assert.deepEqual(exam.max(), [4]);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

assert.deepEqual(exam.max(), [8]);
Expand All @@ -80,14 +83,14 @@ describe('Exam Tool', () => {
it('should calculate the values is less than a value', () => {
exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

assert.deepEqual(exam.lt(7), [4]);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

assert.deepEqual(exam.lt(7), [4]);
Expand All @@ -96,14 +99,14 @@ describe('Exam Tool', () => {
it('should calculate the values is greater than a value', () => {
exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

assert.deepEqual(exam.gt(7), []);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

assert.deepEqual(exam.gt(7), [8]);
Expand Down
6 changes: 4 additions & 2 deletions src/pages/exercises/object-exam/_codes/js/response/exam.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ export class Exam {
}

add(exam) {
exam.grade = Object.keys(exam.answer).reduce((total, q) => {
return total + (exam.answer[q] === this.answer[q] ? this.weight[q] : 0);
exam.grade = Object.keys(exam.values).reduce((total, q) => {
return (
total + (exam.values[q] === this.answer.values[q] ? this.weight[q] : 0)
);
}, 0);

this.exams.push(exam);
Expand Down
11 changes: 8 additions & 3 deletions src/pages/exercises/object-exam/_codes/js/response/exam.print.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import { Exam } from './exam.js';
// Exam Tool

const weight = { q1: 2, q2: 2, q3: 2, q4: 2, q5: 2 };
const answer = { q1: 'a', q2: 'b', q3: 'a', q4: 'c', q5: 'd' };

const answer = {
person: 'Professor',
values: { q1: 'a', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
};

const exam = new Exam(answer, weight);

exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

console.log(exam.avg());
Expand All @@ -28,7 +33,7 @@ console.log([]);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

console.log(exam.avg());
Expand Down
29 changes: 16 additions & 13 deletions src/pages/exercises/object-exam/_codes/js/response/exam.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ describe('Exam Tool', () => {
beforeEach(() => {
const weight = { q1: 2, q2: 2, q3: 2, q4: 2, q5: 2 };

const answer = { q1: 'a', q2: 'b', q3: 'a', q4: 'c', q5: 'd' };
const answer = {
person: 'Professor',
values: { q1: 'a', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
};

exam = new Exam(answer, weight);
});

it('should calculate average', () => {
exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

assert.equal(exam.avg(), 4);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

assert.equal(exam.avg(), 6);
Expand All @@ -32,14 +35,14 @@ describe('Exam Tool', () => {
it('should calculate minimum value', () => {
exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

assert.deepEqual(exam.min(), [4]);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

assert.deepEqual(exam.min(), [4]);
Expand All @@ -48,14 +51,14 @@ describe('Exam Tool', () => {
it('should calculate minimum value', () => {
exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

assert.deepEqual(exam.min(), [4]);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

assert.deepEqual(exam.min(), [4]);
Expand All @@ -64,14 +67,14 @@ describe('Exam Tool', () => {
it('should calculate maximum value', () => {
exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

assert.deepEqual(exam.max(), [4]);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

assert.deepEqual(exam.max(), [8]);
Expand All @@ -80,14 +83,14 @@ describe('Exam Tool', () => {
it('should calculate the values is less than a value', () => {
exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

assert.deepEqual(exam.lt(7), [4]);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

assert.deepEqual(exam.lt(7), [4]);
Expand All @@ -96,14 +99,14 @@ describe('Exam Tool', () => {
it('should calculate the values is greater than a value', () => {
exam.add({
student: 'Alice',
answer: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
values: { q1: 'a', q2: 'b', q3: 'b', q4: 'b', q5: 'b' },
});

assert.deepEqual(exam.gt(7), []);

exam.add({
student: 'Bob',
answer: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
values: { q1: 'c', q2: 'b', q3: 'a', q4: 'c', q5: 'd' },
});

assert.deepEqual(exam.gt(7), [8]);
Expand Down

0 comments on commit 66154ea

Please sign in to comment.