mirror of
https://github.com/bambuscontrol/obsidian-unicode-search.git
synced 2026-07-22 07:20:27 +00:00
Comparison tests
This commit is contained in:
parent
3af2581e28
commit
8fedd767f0
9 changed files with 151 additions and 4 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -20,3 +20,5 @@
|
|||
.DS_Store
|
||||
|
||||
/.ignore/
|
||||
|
||||
/coverage/
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
"scripts": {
|
||||
"dev": "node esbuild.config.mjs",
|
||||
"build": "tsc -noEmit -skipLibCheck && node esbuild.config.mjs production",
|
||||
"export-schema": "typescript-json-schema --required --strictNullChecks --validationKeywords --ignoreErrors --refs --id https://raw.githubusercontent.com/BambusControl/obsidian-unicode-search/0.5.0-NEXT/resources/save-data-schema.json --out ./resources/save-data-schema.json tsconfig.json SaveData"
|
||||
"export-schema": "typescript-json-schema --required --strictNullChecks --validationKeywords --ignoreErrors --refs --id https://raw.githubusercontent.com/BambusControl/obsidian-unicode-search/0.5.0-NEXT/resources/save-data-schema.json --out ./resources/save-data-schema.json tsconfig.json SaveData",
|
||||
"test": "jest"
|
||||
},
|
||||
"keywords": [
|
||||
"obsidian"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,31 @@
|
|||
import {compareUsageTrackedCharacters} from "./compare-usage-tracked.characters";
|
||||
|
||||
test(
|
||||
"later use is before sooner use",
|
||||
() => {
|
||||
expect(compareUsageTrackedCharacters(
|
||||
{
|
||||
lastUsed: 1,
|
||||
useCount: 1,
|
||||
},
|
||||
{
|
||||
lastUsed: 0,
|
||||
useCount: 1,
|
||||
}
|
||||
)).toBe(-1)
|
||||
}
|
||||
)
|
||||
|
||||
test(
|
||||
"one use is before zero uses",
|
||||
() => {
|
||||
expect(compareUsageTrackedCharacters(
|
||||
{
|
||||
useCount: 1,
|
||||
},
|
||||
{
|
||||
useCount: 0,
|
||||
}
|
||||
)).toBe(-1)
|
||||
}
|
||||
)
|
||||
|
|
@ -4,7 +4,7 @@ import {inverse} from "../order/inverse";
|
|||
import {compareNullable} from "./compare.nullable";
|
||||
import {compareNumbers} from "./compare.numbers";
|
||||
|
||||
export function compareStatTrackedCharacters(left: UsageInfo, right: UsageInfo): Order {
|
||||
export function compareUsageTrackedCharacters(left: UsageInfo, right: UsageInfo): Order {
|
||||
// We want the most recently used to be first.
|
||||
const lastUsedComparison = compareNullable(
|
||||
left.lastUsed,
|
||||
55
src/libraries/comparison/compare.characters.spec.ts
Normal file
55
src/libraries/comparison/compare.characters.spec.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
import {compareCharacters} from "./compare.characters";
|
||||
|
||||
test(
|
||||
"character with name `a` is before character with name `b`",
|
||||
() => {
|
||||
expect(compareCharacters(
|
||||
{
|
||||
char: " ",
|
||||
name: "a"
|
||||
},
|
||||
{
|
||||
char: " ",
|
||||
name: "b"
|
||||
}
|
||||
)).toBe(-1)
|
||||
}
|
||||
)
|
||||
|
||||
test(
|
||||
"character with `use` is before character without",
|
||||
() => {
|
||||
expect(compareCharacters(
|
||||
{
|
||||
char: " ",
|
||||
name: "b",
|
||||
lastUsed: 1,
|
||||
useCount: 1
|
||||
},
|
||||
{
|
||||
char: " ",
|
||||
name: "a",
|
||||
}
|
||||
)).toBe(-1)
|
||||
}
|
||||
)
|
||||
|
||||
test(
|
||||
"characters with same `name` and `use` are equal",
|
||||
() => {
|
||||
expect(compareCharacters(
|
||||
{
|
||||
char: " ",
|
||||
name: "name",
|
||||
lastUsed: 1,
|
||||
useCount: 1
|
||||
},
|
||||
{
|
||||
char: " ",
|
||||
name: "name",
|
||||
lastUsed: 1,
|
||||
useCount: 1
|
||||
}
|
||||
)).toBe(0)
|
||||
}
|
||||
)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import {Order} from "../order/order";
|
||||
import {UsageInfo} from "../types/usage-info";
|
||||
import {compareNullable} from "./compare.nullable";
|
||||
import {compareStatTrackedCharacters} from "./compare-stat-tracked.characters";
|
||||
import {compareUsageTrackedCharacters} from "./compare-usage-tracked.characters";
|
||||
import {compareUnicodeNames} from "./compare-unicode.names";
|
||||
import {Character} from "../types/character";
|
||||
|
||||
|
|
@ -9,7 +9,7 @@ export function compareCharacters(left: Character, right: Character): Order {
|
|||
const order = compareNullable(
|
||||
left as UsageInfo,
|
||||
right as UsageInfo,
|
||||
(l, r) => compareStatTrackedCharacters(l, r),
|
||||
(l, r) => compareUsageTrackedCharacters(l, r),
|
||||
);
|
||||
|
||||
if (order != Order.Equal) {
|
||||
|
|
|
|||
24
src/libraries/comparison/compare.nullable.spec.ts
Normal file
24
src/libraries/comparison/compare.nullable.spec.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import {expect, test} from "@jest/globals";
|
||||
import {compareNullable} from "./compare.nullable";
|
||||
import {compareNumbers} from "./compare.numbers";
|
||||
|
||||
test(
|
||||
"null equals null",
|
||||
() => {
|
||||
expect(compareNullable(null, null, compareNumbers)).toBe(0);
|
||||
}
|
||||
)
|
||||
|
||||
test(
|
||||
"non-null is less than null",
|
||||
() => {
|
||||
expect(compareNullable(0, null, compareNumbers)).toBe(-1);
|
||||
}
|
||||
)
|
||||
|
||||
test(
|
||||
"null is more than non-null",
|
||||
() => {
|
||||
expect(compareNullable(null, 0, compareNumbers)).toBe(1);
|
||||
}
|
||||
)
|
||||
23
src/libraries/comparison/compare.numbers.spec.ts
Normal file
23
src/libraries/comparison/compare.numbers.spec.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import {expect, test} from "@jest/globals";
|
||||
import {compareNumbers} from "./compare.numbers";
|
||||
|
||||
test(
|
||||
"one equals one",
|
||||
() => {
|
||||
expect(compareNumbers(1, 1)).toBe(0);
|
||||
}
|
||||
)
|
||||
|
||||
test(
|
||||
"zero is less than one",
|
||||
() => {
|
||||
expect(compareNumbers(0, 1)).toBe(-1);
|
||||
}
|
||||
)
|
||||
|
||||
test(
|
||||
"two is more than one",
|
||||
() => {
|
||||
expect(compareNumbers(2, 1)).toBe(1);
|
||||
}
|
||||
)
|
||||
11
src/libraries/helpers/hexadecimal.characters.spec.ts
Normal file
11
src/libraries/helpers/hexadecimal.characters.spec.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import {toHexadecimal} from "./hexadecimal.characters";
|
||||
|
||||
test(
|
||||
"character `b` is `0062`",
|
||||
() => {
|
||||
expect(toHexadecimal({
|
||||
"char": "b",
|
||||
"name": "latin small letter b"
|
||||
})).toBe("0062")
|
||||
}
|
||||
)
|
||||
Loading…
Reference in a new issue