Skip to content

Commit aa71a67

Browse files
authored
Merge branch '510558017' into lab4
2 parents e5e3c94 + f930783 commit aa71a67

File tree

3 files changed

+51
-18
lines changed

3 files changed

+51
-18
lines changed

lab1/main.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,14 @@ class Student {
4242
}
4343
}
4444

45-
// const myClass = new MyClass();
46-
// const names = ['John', 'Jane', 'Doe', 'Smith'];
47-
// names.forEach(name => {
48-
// const student = new Student();
49-
// student.setName(name);
50-
// const newStudentId = myClass.addStudent(student);
51-
// const newStudentName = myClass.getStudentById(newStudentId).getName();
52-
// console.log('[+] Added student with id: %d, name: %s', newStudentId, newStudentName);
45+
//const myClass = new MyClass();
46+
//const names = ['John', 'Jane', 'Doe', 'Smith'];
47+
//names.forEach(name => {
48+
// const student = new Student();
49+
//student.setName(name);
50+
// const newStudentId = myClass.addStudent(student);
51+
//const newStudentName = myClass.getStudentById(newStudentId).getName();
52+
// console.log('[+] Added student with id: %d, name: %s', newStudentId, newStudentName);
5353
// });
5454

55-
module.exports = { MyClass, Student };
55+
module.exports = { MyClass, Student };

lab1/main_test.js

+27-9
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,39 @@ const assert = require('assert');
33
const { MyClass, Student } = require('./main');
44

55
test("Test MyClass's addStudent", () => {
6-
// TODO
7-
throw new Error("Test not implemented");
6+
const myClass = new MyClass();
7+
const student = new Student();
8+
student.setName("John");
9+
const index = myClass.addStudent(student);
10+
assert.strictEqual(index, 0, "addStudent should return index 0 for the first student");
11+
const notAStudent = {};
12+
const indexForNotAStudent = myClass.addStudent(notAStudent);
13+
assert.strictEqual(indexForNotAStudent, -1, "addStudent should return -1 when adding a non-Student instance");
814
});
915

1016
test("Test MyClass's getStudentById", () => {
11-
// TODO
12-
throw new Error("Test not implemented");
17+
const myClass = new MyClass();
18+
const student = new Student();
19+
student.setName("Jane");
20+
const index = myClass.addStudent(student);
21+
const fetchedStudent = myClass.getStudentById(index);
22+
assert.strictEqual(fetchedStudent.getName(), "Jane", "getStudentById should retrieve the student with the correct name");
23+
const invalidFetchedStudent = myClass.getStudentById(-1);
24+
assert.strictEqual(invalidFetchedStudent, null, "getStudentById should return null for an invalid id");
1325
});
1426

1527
test("Test Student's setName", () => {
16-
// TODO
17-
throw new Error("Test not implemented");
28+
const student = new Student();
29+
student.setName("Doe");
30+
assert.strictEqual(student.name, "Doe", "setName should correctly set the student's name");
31+
student.setName(123);
32+
assert.strictEqual(student.name, "Doe", "setName should not set name when the input is not a string");
1833
});
1934

2035
test("Test Student's getName", () => {
21-
// TODO
22-
throw new Error("Test not implemented");
23-
});
36+
const student = new Student();
37+
student.setName("Smith");
38+
assert.strictEqual(student.getName(), "Smith", "getName should return the correct name");
39+
const newStudent = new Student();
40+
assert.strictEqual(newStudent.getName(), '', "getName should return an empty string for a student without a name");
41+
});

lab4/main_test.js

+15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const puppeteer = require('puppeteer');
99
// Navigate the page to a URL
1010
await page.goto('https://pptr.dev/');
1111

12+
1213
// Click search button
1314
await page.click('button.DocSearch.DocSearch-Button');
1415

@@ -35,3 +36,17 @@ const puppeteer = require('puppeteer');
3536
// Close the browser
3637
await browser.close();
3738
})();
39+
40+
// Hints:
41+
// Click search button
42+
// Type into search box
43+
// Wait for search result
44+
// Get the `Docs` result section
45+
// Click on first result in `Docs` section
46+
// Locate the title
47+
// Print the title
48+
49+
// Close the browser
50+
await browser.close();
51+
})();
52+

0 commit comments

Comments
 (0)