diff --git a/src/pages/exercises/object-exam/_assets/object-exams.pu b/src/pages/exercises/object-exam/_assets/object-exams.pu index 36cf076..5e600ad 100644 --- a/src/pages/exercises/object-exam/_assets/object-exams.pu +++ b/src/pages/exercises/object-exam/_assets/object-exams.pu @@ -3,12 +3,12 @@ skinparam classAttributeIconSize 0 skinparam monochrome true hide circle -class Exams { +class Exam { -weight: Weight -answer: Answer - -exams: Exam + -exams: Array +__construct(answer: Answer, weight: Weight) - +add(exam: Exam): void + +add(exam: Answer): void +avg(): float +min([count: float]): Array +max([count: float]): Array diff --git a/src/pages/exercises/object-exam/_assets/object-exams.svg b/src/pages/exercises/object-exam/_assets/object-exams.svg index 70826c1..a484695 100644 --- a/src/pages/exercises/object-exam/_assets/object-exams.svg +++ b/src/pages/exercises/object-exam/_assets/object-exams.svg @@ -1 +1 @@ -Exams-weight: Weight-answer: Answer-exams: Exam+__construct(answer: Answer, weight: Weight)+add(exam: Exam): void+avg(): float+min([count: float]): Array<float>+max([count: float]): Array<float>+lt([limit: float]): Array<float>+gt([limit: float]): Array<float> \ No newline at end of file +Exam-weight: Weight-answer: Answer-exams: Array<Answer>+__construct(answer: Answer, weight: Weight)+add(exam: Answer): void+avg(): float+min([count: float]): Array<float>+max([count: float]): Array<float>+lt([limit: float]): Array<float>+gt([limit: float]): Array<float> \ No newline at end of file diff --git a/src/pages/exercises/object-exam/_codes/js/code/exam.print.js b/src/pages/exercises/object-exam/_codes/js/code/exam.print.js index 5e2f612..c8a5166 100644 --- a/src/pages/exercises/object-exam/_codes/js/code/exam.print.js +++ b/src/pages/exercises/object-exam/_codes/js/code/exam.print.js @@ -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()); @@ -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()); diff --git a/src/pages/exercises/object-exam/_codes/js/code/exam.test.js b/src/pages/exercises/object-exam/_codes/js/code/exam.test.js index 17cb610..6f11824 100644 --- a/src/pages/exercises/object-exam/_codes/js/code/exam.test.js +++ b/src/pages/exercises/object-exam/_codes/js/code/exam.test.js @@ -8,7 +8,10 @@ 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); }); @@ -16,14 +19,14 @@ describe('Exam Tool', () => { 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); @@ -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]); @@ -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]); @@ -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]); @@ -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]); @@ -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]); diff --git a/src/pages/exercises/object-exam/_codes/js/response/exam.js b/src/pages/exercises/object-exam/_codes/js/response/exam.js index 0535c67..b7a453e 100644 --- a/src/pages/exercises/object-exam/_codes/js/response/exam.js +++ b/src/pages/exercises/object-exam/_codes/js/response/exam.js @@ -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); diff --git a/src/pages/exercises/object-exam/_codes/js/response/exam.print.js b/src/pages/exercises/object-exam/_codes/js/response/exam.print.js index 5e2f612..c8a5166 100644 --- a/src/pages/exercises/object-exam/_codes/js/response/exam.print.js +++ b/src/pages/exercises/object-exam/_codes/js/response/exam.print.js @@ -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()); @@ -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()); diff --git a/src/pages/exercises/object-exam/_codes/js/response/exam.test.js b/src/pages/exercises/object-exam/_codes/js/response/exam.test.js index 17cb610..6f11824 100644 --- a/src/pages/exercises/object-exam/_codes/js/response/exam.test.js +++ b/src/pages/exercises/object-exam/_codes/js/response/exam.test.js @@ -8,7 +8,10 @@ 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); }); @@ -16,14 +19,14 @@ describe('Exam Tool', () => { 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); @@ -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]); @@ -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]); @@ -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]); @@ -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]); @@ -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]);