Last active
December 9, 2024 13:13
-
-
Save nvie/3005a2d2ad6ee09f189298d14d966c64 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fc from "fast-check"; | |
import isProbablyEnchantedWord from "./advent-day-09.mjs"; | |
import { test, expect } from "bun:test"; | |
const char = fc.stringMatching(/^\w$/); | |
const word = fc.stringMatching(/^\w+$/); | |
const palindrome = fc.oneof( | |
char, | |
fc | |
.tuple(word, fc.string({ maxLength: 1 })) | |
.map(([word, sep]) => word + sep + word.split("").reverse().join("")) | |
.filter((w) => !w.includes("\n")) | |
); | |
// declare isProbablyEnchantedWord(word: string): boolean; | |
test("day 9: false negatives", () => { | |
fc.assert( | |
fc.property(palindrome, (word) => { | |
expect(isProbablyEnchantedWord(word)).toEqual(true); | |
}) | |
); | |
}); | |
test("day 9: false positives", () => { | |
fc.assert( | |
fc.property( | |
word, | |
word, | |
(word1, word2) => { | |
fc.pre(word1.length >= 1); | |
fc.pre(!word1.includes(word2)); | |
expect(isProbablyEnchantedWord(word2 + word1)).toEqual(false); | |
expect(isProbablyEnchantedWord(word1 + word2)).toEqual(false); | |
} | |
) | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Counter example, a false positive: