-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest01.js
More file actions
80 lines (74 loc) · 2.41 KB
/
test01.js
File metadata and controls
80 lines (74 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Algorithm construction
// const { expect } = require('chai');
const judgeVegetable = function (vegetables, metric) {
let highest = 0;
let winner = '';
vegetables.forEach(function (vegetable) {
if (vegetable[metric] > highest) {
highest = vegetable[metric];
winner = vegetable.submitter;
}
});
return winner;
}
// let vegetables = [
// {
// submitter: 'Old Man Franklin',
// redness: 10,
// plumpness: 5
// },
// {
// submitter: 'Sally Tomato-Grower',
// redness: 2,
// plumpness: 8
// },
// {
// submitter: 'Hamid Hamidson',
// redness: 4,
// plumpness: 3
// }
// ]
// let metric = 'redness'
// let result = judgeVegetable(vegetables, metric)
// expect(result).to.equal('Old Man Franklin')
// vegetables = [
// {
// submitter: 'A',
// d: 5,
// },
// {
// submitter: 'B',
// d: 10,
// },
// {
// submitter: 'C',
// d: 25,
// }
// ]
// metric = 'd'
// result = judgeVegetable(vegetables, metric)
// expect(result).to.equal('C')
// Test
// Import the Mocha library and the Chai assertion library
import { expect } from 'chai';
import { describe, it } from 'mocha';
// Import the function to be tested
// const judgeVegetable = require('./judgeVegetable');
console.log("judgeVegetable start testing");
// Define the test suite
describe('judgeVegetable', () => {
// Define the test case for redness
it('returns the submitter with the highest redness value', () => {
const vegetables = [ { submitter: 'Old Man Franklin', redness: 10, plumpness: 5, }, { submitter: 'Sally Tomato-Grower', redness: 2, plumpness: 8, }, { submitter: 'Hamid Hamidson', redness: 4, plumpness: 3, }, ];
const metric = 'redness';
const winner = judgeVegetable(vegetables, metric);
expect(winner).to.equal('Old Man Franklin');
});
// Define the test case for plumpness
it('returns the submitter with the highest plumpness value', () => {
const vegetables = [ { submitter: 'Alice', redness: 5, plumpness: 10, }, { submitter: 'Bob', redness: 8, plumpness: 5, }, { submitter: 'Charlie', redness: 2, plumpness: 20, }, ];
const metric = 'plumpness';
const winner = judgeVegetable(vegetables, metric);
expect(winner).to.equal('Charlie');
});
});