Skip to content

Commit

Permalink
add jest unit tests for euclid, extendedEuclid, precrt and crt, add t…
Browse files Browse the repository at this point in the history
…est workflow to actions and update readme accordingly
  • Loading branch information
goseind committed Nov 24, 2023
1 parent 164bdd2 commit 479369d
Show file tree
Hide file tree
Showing 5 changed files with 7,135 additions and 3,097 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/jest-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Tests

on:
workflow_dispatch:
pull_request_target:
paths:
- 'kryptolearn/**'

jobs:
build:
name: Install and build
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./kryptolearn
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18.x
cache: npm
cache-dependency-path: kryptolearn/package-lock.json
- name: Run jest tests
run: npm test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![EAS Build](https://github.com/goseind/kryptolearn/actions/workflows/eas-build.yml/badge.svg)](https://github.com/goseind/kryptolearn/actions/workflows/eas-build.yml) [![EAS Submit](https://github.com/goseind/kryptolearn/actions/workflows/eas-submit.yml/badge.svg)](https://github.com/goseind/kryptolearn/actions/workflows/eas-submit.yml) [![pages-build-deployment](https://github.com/goseind/kryptolearn/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/goseind/kryptolearn/actions/workflows/pages/pages-build-deployment)
[![EAS Build](https://github.com/goseind/kryptolearn/actions/workflows/eas-build.yml/badge.svg)](https://github.com/goseind/kryptolearn/actions/workflows/eas-build.yml) [![EAS Submit](https://github.com/goseind/kryptolearn/actions/workflows/eas-submit.yml/badge.svg)](https://github.com/goseind/kryptolearn/actions/workflows/eas-submit.yml) [![pages-build-deployment](https://github.com/goseind/kryptolearn/actions/workflows/pages/pages-build-deployment/badge.svg)](https://github.com/goseind/kryptolearn/actions/workflows/pages/pages-build-deployment) [![Tests](https://github.com/goseind/kryptolearn/actions/workflows/jest-test.yml/badge.svg)](https://github.com/goseind/kryptolearn/actions/workflows/jest-test.yml) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg?logo=jest)](https://github.com/jestjs/jest)

# Krypto Learn

Expand Down
19 changes: 19 additions & 0 deletions kryptolearn/__tests__/algorithms.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

import { Euclid, extendedEuclid, precrt, crt } from "../algorithms";

test('calculates gcd(5567, 57684) equals 19 with correct steps', () => {
expect(Euclid(5567, 57684)).toEqual([19,["Schritt 1: 5567 = 0 * 57684 + 5567", "Schritt 2: 57684 = 10 * 5567 + 2014", "Schritt 3: 5567 = 2 * 2014 + 1539", "Schritt 4: 2014 = 1 * 1539 + 475", "Schritt 5: 1539 = 3 * 475 + 114", "Schritt 6: 475 = 4 * 114 + 19", "Schritt 7: 114 = 6 * 19 + 0"]]);
});

test('calculate x = 371 and y = -25 for 456 and 6767', () => {
expect(extendedEuclid(456, 6767).x).toBe(371);
expect(extendedEuclid(456, 6767).y).toBe(-25);
});

test('calcualte product of mods 2,3,5,7 to be 210, 105, 70, 42, 30', () => {
expect(precrt([2,3,5,7]).bigM).toEqual([20, 105, 70, 42, 30]);
});

test('calculate crt of mods 2,3,5,7 and remainders 1,1,1,0 sum equal to 91', () => {
expect(crt([2,3,5,7], [1,1,1,0]).x).toBe(91);
});
Loading

0 comments on commit 479369d

Please sign in to comment.