diff --git a/.github/workflows/lab-autograding.yml b/.github/workflows/lab-autograding.yml index ba7a31f9..033b2a2e 100644 --- a/.github/workflows/lab-autograding.yml +++ b/.github/workflows/lab-autograding.yml @@ -12,13 +12,17 @@ jobs: os: [ubuntu-22.04] fail-fast: false steps: - - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 with: ref: "${{ github.event.pull_request.merge_commit_sha }}" fetch-depth: 1 - - uses: actions/setup-node@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 with: - node-version: latest + node-version: '20' + - name: Extract lab number and Check no changes other than specific files uses: actions/github-script@v5 id: lab @@ -40,16 +44,17 @@ jobs: return { number: 0 }; } const labNumber = labNumberMatch[1]; - console.log(`Lab number: ${labNumber}`) + console.log(`Lab number: ${labNumber}`); const files = await github.rest.pulls.listFiles({ owner, repo, pull_number: issue_number }); const changedFiles = files.data.map((file) => file.filename); const allowedFileRegex = /^lab\d+\/main_test.js$/; const specialChangedFiles = ["lab5/Answer.md", "lab5/antiasan.c", "lab6/Answer.md", "lab7/sol.py"]; - if (!changedFiles.every((file) => (allowedFileRegex.test(file) || specialChangedFiles.includes(file)))) { + if (!changedFiles.every((file) => allowedFileRegex.test(file) || specialChangedFiles.includes(file))) { core.setFailed('The PR contains changes to files other than the allowed files.'); } return labNumber; + - name: Grading run: | cd lab${{ steps.lab.outputs.result }} diff --git a/lab3/main_test.js b/lab3/main_test.js index 096fd421..9b2cb75d 100644 --- a/lab3/main_test.js +++ b/lab3/main_test.js @@ -2,4 +2,62 @@ const { describe, it } = require('node:test'); const assert = require('assert'); const { Calculator } = require('./main'); + +describe('Calculator', () => { + const calculator = new Calculator(); + + describe('exp function', () => { + it('calculates the exponential of a number', async () => { + assert.strictEqual(calculator.exp(1), Math.exp(1)); + }); + + it('throws error on non-finite input', async () => { + assert.throws(() => calculator.exp('a'), { + name: 'Error', + message: 'unsupported operand type' + }); + assert.throws(() => calculator.exp(Infinity), { + name: 'Error', + message: 'unsupported operand type' + }); + }); + + it('handles overflow', async () => { + assert.throws(() => calculator.exp(1000), { + name: 'Error', + message: 'overflow' + }); + }); + }); + + describe('log function', () => { + it('calculates the logarithm of a number', async () => { + assert.strictEqual(calculator.log(Math.E), Math.log(Math.E)); + }); + + it('throws error on non-finite input', async () => { + assert.throws(() => calculator.log('a'), { + name: 'Error', + message: 'unsupported operand type' + }); + assert.throws(() => calculator.log(-1), { + name: 'Error', + message: 'math domain error (1)' + }); + }); + + it('handles domain errors', async () => { + assert.throws(() => calculator.log(0), { + name: 'Error', + message: 'math domain error (1)' + }); + assert.throws(() => calculator.log(null), { + name: 'Error', + message: 'unsupported operand type' + }); + }); + }); +}); + + // TODO: write your tests here