Skip to content

[LAB5] 313505006 #385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
May 1, 2025
45 changes: 31 additions & 14 deletions lab1/main_test.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
const test = require('node:test');
const assert = require('assert');
const { MyClass, Student } = require('./main');

test("Test MyClass's addStudent", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const student = new Student();
student.setName("John");

const id = myClass.addStudent(student);
assert.strictEqual(id, 0, "First student should have ID 0");

const id2 = myClass.addStudent(new Student());
assert.strictEqual(id2, 1, "Second student should have ID 1");

const invalidId = myClass.addStudent({});
assert.strictEqual(invalidId, -1, "Adding non-Student instance should return -1");
});

test("Test MyClass's getStudentById", () => {
// TODO
throw new Error("Test not implemented");
const myClass = new MyClass();
const student = new Student();
student.setName("Jane");
myClass.addStudent(student);

assert.strictEqual(myClass.getStudentById(0).getName(), "Jane", "Student with ID 0 should be Jane");
assert.strictEqual(myClass.getStudentById(1), null, "Fetching non-existent student should return null");
assert.strictEqual(myClass.getStudentById(-1), null, "Fetching with negative ID should return null");
});

test("Test Student's setName", () => {
// TODO
throw new Error("Test not implemented");
const student = new Student();
student.setName("Doe");
assert.strictEqual(student.getName(), "Doe", "Student name should be Doe");

student.setName(123);
assert.strictEqual(student.getName(), "Doe", "Student name should remain Doe if setName is called with non-string");
});

test("Test Student's getName", () => {
// TODO
throw new Error("Test not implemented");
});
const student = new Student();
assert.strictEqual(student.getName(), "", "Default student name should be empty string");

student.setName("Smith");
assert.strictEqual(student.getName(), "Smith", "Student name should be Smith after setting it");
10 changes: 8 additions & 2 deletions lab5/antiasan.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
#include <string.h>
#include <sanitizer/asan_interface.h>
#include "antiasan.h"

extern char gS[0x18];
extern char gBadBuf[0x87];

void antiasan(unsigned long addr)
{

__asan_unpoison_memory_region((void *)addr, 0x87);
__asan_unpoison_memory_region(gS + 0x18, 0x10);
}