Skip to content

Commit

Permalink
Added tests (Fixes #1)
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Sanino <[email protected]>
  • Loading branch information
saniales committed Sep 24, 2020
1 parent 0c01bc5 commit 4ab51c1
Show file tree
Hide file tree
Showing 8 changed files with 51,533 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
with:
node-version: 14
- run: yarn install --frozen-lockfile
#- run: yarn test
- run: yarn test

publish-npm:
needs: build
Expand Down
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
testdata/*
*.test.ts
27 changes: 27 additions & 0 deletions index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, it } from "mocha";
import small_test from "./testdata/small_test";
import big_test from "./testdata/big_test";
import { expect } from "chai";
import gestaltSimilarity from ".";

describe("Library Tests (Average string length = 18 characters)", () => {
it(`Short Test (${small_test.length} elements)`, () => {
test_from_cases(small_test);
})
it(`Big Test (${big_test.length} elements)`, () => {
test_from_cases(big_test);
})
});

type TestCase = {
first: string;
second: string;
expected_result: number;
}

function test_from_cases(cases : TestCase[]) {
for (const { first, second, expected_result } of cases) {
const actual_result = gestaltSimilarity(first, second);
expect(actual_result).to.be.equal(expected_result, `gestaltSimilarity("${first}", "${second}") did not pass the test`);
}
}
20 changes: 17 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "gestalt-pattern-matcher",
"version": "0.0.9",
"version": "0.0.10",
"license": "MIT",
"repository": {
"type": "git",
"url": "[email protected]:saniales/gestalt-pattern-matcher.git"
Expand All @@ -15,14 +16,27 @@
"url": "https://alessandro.sanino.dev"
},
"description": "Finds the similarity between strings and represents it as a number",
"keywords": [ "pattern-matching", "gestalt", "string-similarity", "similarity" ],
"license": "MIT",
"keywords": [
"pattern-matching",
"gestalt",
"string-similarity",
"similarity"
],
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"test": "mocha -r ts-node/register '*.test.ts'",
"prepublish": "tsc"
},
"devDependencies": {
"@types/chai": "^4.2.12",
"@types/mocha": "^8.0.3",
"chai": "^4.2.0",
"mocha": "^8.1.3",
"ts-node": "^9.0.0",
"typescript": "^4.0.3"
},
"dependencies": {
"faker": "^5.1.0"
}
}
Loading

0 comments on commit 4ab51c1

Please sign in to comment.