Skip to content

Test #50

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Test #50

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/coding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ jobs:
uses: actions/setup-node@v4
with:
cache: npm
cache-dependency-path: package-lock.json
node-version-file: '.nvmrc'
- name: Install dependencies
run: |
Expand All @@ -79,6 +80,7 @@ jobs:
- name: Run tests - TypeScript Challenges (NPM)
run: |
cd programming/typescript/challenges
npm run build
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Potential Redundant Build Step
The npm run build command added in the "Run tests - TypeScript Challenges (NPM)" step might be redundant since a similar build step is executed earlier in the workflow. Please verify if the rebuild is necessary—for example, to pick up any changes made after the first build—or if it can be safely removed to streamline the workflow.

npm test
npm run test:jest
- name: Reporter (Verify test results)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docker-images",
"version": "3.3.1-rc.2",
"version": "3.3.1-rc.3",
"packageManager": "[email protected]",
"private": true,
"repository": {
Expand Down
6 changes: 5 additions & 1 deletion programming/typescript/challenges/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@ coverage/*
coverage/
.coverage
*.lcov
test-results/
test-results/
# typescript compiled files
dist/
# node_modules
node_modules/
Binary file modified programming/typescript/challenges/.yarn/install-state.gz
Binary file not shown.
19 changes: 0 additions & 19 deletions programming/typescript/challenges/index.js

This file was deleted.

62 changes: 61 additions & 1 deletion programming/typescript/challenges/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Challenges from '@lehungio/typescript';
import { greet, wordCount } from '@lehungio/typescript';

describe('Challenges Module', () => {
describe('Challenges output', () => {
test('greet function should return correct greeting', () => {
const helloAll = Challenges.greet('All');
expect(helloAll).toBe('Hello, All!');
Expand All @@ -23,4 +23,64 @@ describe('Challenges Module', () => {
const expectedCount = new Map([['hello', 1], ['world', 1]]);
expect(count).toEqual(expectedCount);
});

test('differenceOfSquares function should return correct difference of squares', () => {
const squares = new Challenges.Squares(5);
expect(squares.squareOfSum).toBe(225);
expect(squares.sumOfSquares).toBe(55);
expect(squares.difference).toBe(170);
});
Comment on lines +27 to +32
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider additional edge case checks.

Testing differenceOfSquares only with 5 may miss boundary or negative inputs. Extending test coverage can increase confidence in correctness.


});

describe('Challenge #27 - Gigasecond output test', () => {
test('Gigasecond function should return correct gigasecond date', () => {
const gigasecond = new Challenges.Gigasecond(new Date('2013-01-07'));
expect(gigasecond.date().toISOString()).toBe("2044-09-15T01:46:40.000Z");
});
});

describe('Challenge #28 - Reverse String output test', () => {
test('reverse function should return correct reversed string', () => {
const reversed = Challenges.reverse('hello');
expect(reversed).toBe('olleh');
});

test('reverse function should return correct reversed string', () => {
const reversed = Challenges.reverse('aloha');
expect(reversed).toBe('ahola');
});
});

describe('Challenge #29 - Triangle output test', () => {
test('Triangle class should return correct triangle type', () => {
const triangle = new Challenges.Triangle(3, 4, 5);
expect(triangle.isEquilateral).toBe(false);
expect(triangle.isIsosceles).toBe(false);
expect(triangle.isScalene).toBe(true);
});
});

describe('Challenge #30 - Collatz Conjecture output test', () => {
test('steps function should return correct number of steps', () => {
expect(Challenges.steps(16)).toBe(4);
expect(Challenges.steps(12)).toBe(9);
expect(Challenges.steps(1000000)).toBe(152);
});
});

describe('Challenge #42 - ETL output test', () => {
test('transform function should return correct transformed data', () => {
const oldSystem = { 1: ['A'] };
const newSystem = Challenges.transform(oldSystem);
expect(newSystem).toEqual({ a: 1 });
});
});

describe('Challenge #43 - Protein Translation output test', () => {
test('translateRNA function should return correct translated RNA', () => {
const rnaInput = 'AUGUUUUGG';
const translated = Challenges.translateRNA(rnaInput);
expect(translated).toEqual(['Methionine', 'Phenylalanine', 'Tryptophan']);
});
});
87 changes: 86 additions & 1 deletion programming/typescript/challenges/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,89 @@ try {
* Demonstrates the word counting functionality
*/
const count = Challenges.wordCount('Hello, World!'); // Output: 2
console.log('Word count result:', count);
console.log('Word count result:', count);

/**
* Challenge 26: Difference of Squares
* Demonstrates the difference of squares functionality
*/
const squares = new Challenges.Squares(5);
console.log('Square of sum:', squares.squareOfSum);
console.log('Sum of squares:', squares.sumOfSquares);
console.log('Difference:', squares.difference);

Comment on lines +27 to +35
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider tests for multiple inputs.
These logs for the difference-of-squares calculation look fine. It might be helpful to add additional examples or edge-case tests to confirm correctness for other numbers.

/**
* Challenge 27: Gigasecond
* Demonstrates the gigasecond functionality
*/
const gigasecond = new Challenges.Gigasecond(new Date('2013-01-07'));
console.log('Gigasecond date from 2013-01-07:', gigasecond.date());
Comment on lines +40 to +41
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

⚠️ Potential issue

🧩 Analysis chain

Verify the gigasecond calculation.

The test is failing because it expects a different date than what's being calculated. Ensure the Gigasecond class correctly adds 10^9 seconds to the input date.


🌐 Web query:

How many days is one gigasecond?

💡 Result:

One gigasecond is equivalent to approximately 11,574.07 days. This conversion is derived by dividing (10^9) seconds (one gigasecond) by the number of seconds in a day (86,400), resulting in ( \frac{1{,}000{,}000{,}000}{86{,}400} \approx 11{,}574.07 ) days[2][3][5]. The exact value extends as a repeating decimal ((11{,}574.\overline{074})), reflecting the precise mathematical relationship between these units[2][3]. This duration highlights how large-scale time measurements translate into more familiar daily terms[1][4].

Citations:


Action: Revise Gigasecond Calculation for Accurate Date Arithmetic

The current implementation is not adding 1,000,000,000 seconds correctly. Recall that one gigasecond is approximately 11,574.07 days—which means you need to add 11,574 full days plus an extra 1 hour, 46 minutes, and 40 seconds. This discrepancy is causing the test failure.

Please verify and adjust your Gigasecond class so that it:

  • Accurately converts 1,000,000,000 seconds into days and the remaining hours/minutes/seconds.
  • Adds the entire duration to the input date without unintended rounding or truncation.

const target = new Date('2025-02-28');
const seconds = Challenges.Gigasecond.secondsToDate(target);
const days = Challenges.Gigasecond.secondsToDays(seconds); // Returns number of days from now until Dec 31, 2024
console.log('Days from now until Feb 28, 2025:', days);

const start = new Date('2013-01-07');
const gs = new Challenges.Gigasecond(start);
const target2 = new Date('2025-02-28');
const seconds2 = gs.secondsBetweenDates(target2); // Returns seconds between Jan 1 and Feb 1
console.log('Seconds between 2013-01-07 and 2025-02-28:', seconds2);
console.log('Days between 2013-01-07 and 2025-02-28:', Challenges.Gigasecond.secondsToDays(seconds2));
Comment on lines +47 to +52
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Inconsistent inline comment in secondsBetweenDates usage.

The comment on line 50 states "Returns seconds between Jan 1 and Feb 1" but the actual code calculates seconds between Jan 7, 2013 and Feb 28, 2025.

-const seconds2 = gs.secondsBetweenDates(target2); // Returns seconds between Jan 1 and Feb 1
+const seconds2 = gs.secondsBetweenDates(target2); // Returns seconds between Jan 7, 2013 and Feb 28, 2025
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const start = new Date('2013-01-07');
const gs = new Challenges.Gigasecond(start);
const target2 = new Date('2025-02-28');
const seconds2 = gs.secondsBetweenDates(target2); // Returns seconds between Jan 1 and Feb 1
console.log('Seconds between 2013-01-07 and 2025-02-28:', seconds2);
console.log('Days between 2013-01-07 and 2025-02-28:', Challenges.Gigasecond.secondsToDays(seconds2));
const start = new Date('2013-01-07');
const gs = new Challenges.Gigasecond(start);
const target2 = new Date('2025-02-28');
const seconds2 = gs.secondsBetweenDates(target2); // Returns seconds between Jan 7, 2013 and Feb 28, 2025
console.log('Seconds between 2013-01-07 and 2025-02-28:', seconds2);
console.log('Days between 2013-01-07 and 2025-02-28:', Challenges.Gigasecond.secondsToDays(seconds2));


/**
* Challenge 28: Reverse String
* Demonstrates the reverse string functionality
*/
const reverseStringInput = 'hello';
console.log(`Challenge 28 - Reverse String: reverse('${reverseStringInput}') => ${Challenges.reverse(reverseStringInput)}`);

/**
* Challenge 29: Triangle
* Demonstrates the triangle functionality
*/
console.log('Challenge 29 - Triangle Check');
const triangle = new Challenges.Triangle(3, 4, 5);
console.log(`Challenge 29 - Triangle: triangle.isEquilateral => ${triangle.isEquilateral}`);
console.log(`Challenge 29 - Triangle: triangle.isIsosceles => ${triangle.isIsosceles}`);
console.log(`Challenge 29 - Triangle: triangle.isScalene => ${triangle.isScalene}`);

/**
* Challenge 30: Collatz Conjecture
* Demonstrates the collatz conjecture functionality
*/
console.log('Challenge 30 - Collatz Conjecture');
const collatzConjectureInput = 16;
console.log(`Challenge 30 - Collatz Conjecture: steps(${collatzConjectureInput}) => ${Challenges.steps(collatzConjectureInput)}`);
const collatzConjectureInput2 = 12;
console.log(`Challenge 30 - Collatz Conjecture: steps(${collatzConjectureInput2}) => ${Challenges.steps(collatzConjectureInput2)}`);
const collatzConjectureInput3 = 1000000;
console.log(`Challenge 30 - Collatz Conjecture: steps(${collatzConjectureInput3}) => ${Challenges.steps(collatzConjectureInput3)}`);
const collatzConjectureInput4 = 2025;
console.log(`Challenge 30 - Collatz Conjecture: steps(${collatzConjectureInput4}) => ${Challenges.steps(collatzConjectureInput4)}`);

Comment on lines +71 to +84
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Collatz Conjecture demonstration.
This looks good and shows multiple test inputs. Consider expanding tests for negative or zero edge cases if relevant.

/**
* Challenge 42: ETL
* Demonstrates the etl functionality
*/
console.log('Challenge 42 - ETL');
const oldSystem = {
1: ['L'],
2: ['E', 'H', 'U'],
3: ['I', 'O']
};
const newSystem = Challenges.transform(oldSystem);
console.log(`Challenge 42 - ETL: transform(${JSON.stringify(oldSystem)}) => ${JSON.stringify(newSystem)}`);

/**
* Challenge 43: Protein Translation
* Demonstrates the protein translation functionality
*/
console.log('Challenge #43 - Protein Translation');
const rnaInput = 'AUGUUUUGG';
console.log(`Challenge #43 - Protein Translation: translateRNA('${rnaInput}') => ${JSON.stringify(Challenges.translateRNA(rnaInput))}`);
const rnaInput2 = 'AUGUUUUAA';
console.log(`Challenge #43 - Protein Translation: translateRNA('${rnaInput2}') => ${JSON.stringify(Challenges.translateRNA(rnaInput2))}`);
const rnaInput3 = 'AUGUUUUAG';
console.log(`Challenge #43 - Protein Translation: translateRNA('${rnaInput3}') => ${JSON.stringify(Challenges.translateRNA(rnaInput3))}`);
const rnaInput4 = 'AUGUUUUAGUGG';
console.log(`Challenge #43 - Protein Translation: translateRNA('${rnaInput4}') => ${JSON.stringify(Challenges.translateRNA(rnaInput4))}`);
10 changes: 6 additions & 4 deletions programming/typescript/challenges/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions programming/typescript/challenges/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
{
"name": "challenges",
"version": "1.0.0",
"version": "1.3.0-rc.5",
"packageManager": "[email protected]",
"main": "index.js",
"main": "dist/index.js",
"scripts": {
"clean": "rimraf dist",
"build": "tsc index.ts",
"start": "node index.js",
"test": "node index.js",
"execute": "node index.js --report-compact ",
"test:node": "node index.js",
"test:jest": "jest --coverage"
"build": "tsc",
"start": "node dist/index.js",
"test": "node dist/index.js",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Potential Test Script Ambiguity
The "test" script now executes "node dist/index.js". Typically, tests are run using a dedicated framework (like Jest), and having two similar commands ("test" and "test:node") might cause confusion. Please verify that this behavior is intentional—if it is meant for integration testing, consider renaming it or adding documentation to clarify its purpose.

"execute": "node dist/index.js --report-compact ",
"test:node": "node dist/index.js",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Review Test:Node Script
The "test:node" script mirrors the behavior of the "test" script by executing "node dist/index.js". If both are intended to serve distinct testing purposes, it might help to document their differences. Otherwise, consider consolidating or renaming one of these commands to improve clarity.

Comment on lines +9 to +12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consolidate or clarify repetitive script commands.
You currently have multiple scripts (start, test, execute, and test:node) all calling node dist/index.js with minimal variation. This can cause confusion for new contributors. Consider combining or renaming them for clarity.

"test:jest": "jest"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Optional coverage flag.
If you’d like to ensure code coverage by default, consider adding back the coverage flag (--coverage) for your Jest tests, or create a separate script that runs coverage.

},
"author": "[email protected]",
"license": "ISC",
"description": "Typescript Programming challenges",
"dependencies": {
"@lehungio/typescript": "^1.3.0-rc.0"
"@lehungio/typescript": "^1.3.0-rc.5"
},
"devDependencies": {
"@types/jest": "^29.5.14",
Expand Down
6 changes: 4 additions & 2 deletions programming/typescript/challenges/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,10 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@lehungio/typescript@^1.3.0-rc.0":
version "1.3.0-rc.0"
"@lehungio/typescript@^1.3.0-rc.5":
version "1.3.0-rc.5"
resolved "https://registry.npmjs.org/@lehungio/typescript/-/typescript-1.3.0-rc.5.tgz"
integrity sha512-40eI5BOOE2f+fL7Q0ZO26tYiE1KY/kCmGkOGBgmBZTL/0QnUYSJn0Y9fcV3BwGu8VRWrDVUyrvDDkJyQ4U277A==
dependencies:
acorn "^8.14.0"
acorn-walk "^8.3.4"
Expand Down