mirror of
https://github.com/quantum5/correcthorsebatterystaple.git
synced 2025-04-24 10:11:57 -04:00
Remove duplicate words and add unit tests
This commit is contained in:
parent
e8ed9a64e9
commit
338f564f8d
1769
package-lock.json
generated
1769
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -5,7 +5,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rimraf dist && cross-env NODE_ENV=production webpack",
|
"build": "rimraf dist && cross-env NODE_ENV=production webpack",
|
||||||
"serve": "webpack-dev-server",
|
"serve": "webpack-dev-server",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "mocha tests"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "Quantum",
|
"author": "Quantum",
|
||||||
|
@ -17,15 +17,16 @@
|
||||||
"html-loader": "^0.5.5",
|
"html-loader": "^0.5.5",
|
||||||
"html-webpack-plugin": "^3.2.0",
|
"html-webpack-plugin": "^3.2.0",
|
||||||
"mini-css-extract-plugin": "^0.4.5",
|
"mini-css-extract-plugin": "^0.4.5",
|
||||||
|
"mocha": "^5.2.0",
|
||||||
"node-sass": "^4.10.0",
|
"node-sass": "^4.10.0",
|
||||||
"optimize-css-assets-webpack-plugin": "^5.0.1",
|
"optimize-css-assets-webpack-plugin": "^5.0.1",
|
||||||
"postcss-loader": "^3.0.0",
|
"postcss-loader": "^3.0.0",
|
||||||
"rimraf": "^2.6.2",
|
"rimraf": "^2.6.2",
|
||||||
"sass-loader": "^7.1.0",
|
"sass-loader": "^7.1.0",
|
||||||
"style-loader": "^0.23.1",
|
"style-loader": "^0.23.1",
|
||||||
|
"terser-webpack-plugin": "latest",
|
||||||
"webpack": "^4.26.1",
|
"webpack": "^4.26.1",
|
||||||
"webpack-cli": "^3.1.2",
|
"webpack-cli": "^3.1.2"
|
||||||
"terser-webpack-plugin": "latest"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bootstrap": "^4.1.3",
|
"bootstrap": "^4.1.3",
|
||||||
|
|
|
@ -1,20 +1,19 @@
|
||||||
import words from './words'
|
const words = require('./words')
|
||||||
|
|
||||||
const digits = '0123456789'
|
const digits = '0123456789'
|
||||||
const symbols = '`~!@#$%^&*()_+-=,./<>?;:|'
|
const symbols = '`~!@#$%^&*()_+-=,./<>?;:|'
|
||||||
|
|
||||||
export function getWordList (name) {
|
function getWordList (name) {
|
||||||
if (['small'].includes(name)) {
|
if (['small'].includes(name)) {
|
||||||
return words[name]
|
return words[name]
|
||||||
}
|
}
|
||||||
throw new Error(`Invalid word list: ${name}`)
|
throw new Error(`Invalid word list: ${name}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getWords (list, indices) {
|
function getWords (list, indices) {
|
||||||
return Array.from(indices).map(index => list[index % list.length])
|
return Array.from(indices).map(index => list[index % list.length])
|
||||||
}
|
}
|
||||||
|
|
||||||
export function capitalize (string) {
|
function capitalize (string) {
|
||||||
return string[0].toUpperCase() + string.slice(1)
|
return string[0].toUpperCase() + string.slice(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +29,7 @@ function pickChar (options) {
|
||||||
return options[array[0] % options.length]
|
return options[array[0] % options.length]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function generate (options) {
|
function generate (options) {
|
||||||
let words = pickWords(getWordList(options.list), options.count)
|
let words = pickWords(getWordList(options.list), options.count)
|
||||||
|
|
||||||
if (options.capitalize) {
|
if (options.capitalize) {
|
||||||
|
@ -48,11 +47,11 @@ export function generate (options) {
|
||||||
return words.join('')
|
return words.join('')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function lengthBits (list) {
|
function lengthBits (list) {
|
||||||
return Math.log2(list.length)
|
return Math.log2(list.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function computeBits (options) {
|
function computeBits (options) {
|
||||||
const wordBits = lengthBits(getWordList(options.list))
|
const wordBits = lengthBits(getWordList(options.list))
|
||||||
const capsBits = options.capitalize ? 1 : 0
|
const capsBits = options.capitalize ? 1 : 0
|
||||||
const symbolBits = options.symbol ? lengthBits(symbols) : 0
|
const symbolBits = options.symbol ? lengthBits(symbols) : 0
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
export default [
|
module.exports = [
|
||||||
'ability',
|
'ability',
|
||||||
'able',
|
'able',
|
||||||
'about',
|
'about',
|
||||||
|
@ -293,6 +293,7 @@ export default [
|
||||||
'chief',
|
'chief',
|
||||||
'child',
|
'child',
|
||||||
'childhood',
|
'childhood',
|
||||||
|
'chin',
|
||||||
'choice',
|
'choice',
|
||||||
'choose',
|
'choose',
|
||||||
'chose',
|
'chose',
|
||||||
|
@ -425,7 +426,6 @@ export default [
|
||||||
'daughter',
|
'daughter',
|
||||||
'dawn',
|
'dawn',
|
||||||
'day',
|
'day',
|
||||||
'day',
|
|
||||||
'dead',
|
'dead',
|
||||||
'deal',
|
'deal',
|
||||||
'dear',
|
'dear',
|
||||||
|
@ -485,7 +485,6 @@ export default [
|
||||||
'discovery',
|
'discovery',
|
||||||
'discussion',
|
'discussion',
|
||||||
'disease',
|
'disease',
|
||||||
'disgrace',
|
|
||||||
'disk',
|
'disk',
|
||||||
'display',
|
'display',
|
||||||
'disposition',
|
'disposition',
|
||||||
|
@ -626,6 +625,7 @@ export default [
|
||||||
'express',
|
'express',
|
||||||
'expression',
|
'expression',
|
||||||
'exquisite',
|
'exquisite',
|
||||||
|
'extensive',
|
||||||
'extent',
|
'extent',
|
||||||
'external',
|
'external',
|
||||||
'extraordinary',
|
'extraordinary',
|
||||||
|
@ -755,6 +755,7 @@ export default [
|
||||||
'gallant',
|
'gallant',
|
||||||
'game',
|
'game',
|
||||||
'garden',
|
'garden',
|
||||||
|
'gas',
|
||||||
'gate',
|
'gate',
|
||||||
'gather',
|
'gather',
|
||||||
'gave',
|
'gave',
|
||||||
|
@ -772,7 +773,6 @@ export default [
|
||||||
'giant',
|
'giant',
|
||||||
'gift',
|
'gift',
|
||||||
'girl',
|
'girl',
|
||||||
'girl',
|
|
||||||
'give',
|
'give',
|
||||||
'glad',
|
'glad',
|
||||||
'glance',
|
'glance',
|
||||||
|
@ -780,6 +780,7 @@ export default [
|
||||||
'gloom',
|
'gloom',
|
||||||
'glorious',
|
'glorious',
|
||||||
'glory',
|
'glory',
|
||||||
|
'glow',
|
||||||
'god',
|
'god',
|
||||||
'goes',
|
'goes',
|
||||||
'gold',
|
'gold',
|
||||||
|
@ -927,6 +928,7 @@ export default [
|
||||||
'indignation',
|
'indignation',
|
||||||
'individual',
|
'individual',
|
||||||
'industry',
|
'industry',
|
||||||
|
'inevitable',
|
||||||
'inferior',
|
'inferior',
|
||||||
'infinite',
|
'infinite',
|
||||||
'influence',
|
'influence',
|
||||||
|
@ -1000,19 +1002,19 @@ export default [
|
||||||
'larger',
|
'larger',
|
||||||
'last',
|
'last',
|
||||||
'late',
|
'late',
|
||||||
'later',
|
|
||||||
'latter',
|
|
||||||
'laugh',
|
'laugh',
|
||||||
'laughter',
|
'laughter',
|
||||||
'law',
|
'law',
|
||||||
'lawyer',
|
'lawyer',
|
||||||
'lay',
|
'lay',
|
||||||
'leader',
|
'leader',
|
||||||
|
'leaf',
|
||||||
'learn',
|
'learn',
|
||||||
'least',
|
'least',
|
||||||
'leave',
|
'leave',
|
||||||
'left',
|
'left',
|
||||||
'leg',
|
'leg',
|
||||||
|
'leisure',
|
||||||
'length',
|
'length',
|
||||||
'lesson',
|
'lesson',
|
||||||
'lest',
|
'lest',
|
||||||
|
@ -1136,7 +1138,6 @@ export default [
|
||||||
'morning',
|
'morning',
|
||||||
'most',
|
'most',
|
||||||
'mother',
|
'mother',
|
||||||
'mother',
|
|
||||||
'motion',
|
'motion',
|
||||||
'motive',
|
'motive',
|
||||||
'mountain',
|
'mountain',
|
||||||
|
@ -1197,7 +1198,6 @@ export default [
|
||||||
'obedience',
|
'obedience',
|
||||||
'obey',
|
'obey',
|
||||||
'object',
|
'object',
|
||||||
'obs',
|
|
||||||
'observation',
|
'observation',
|
||||||
'observe',
|
'observe',
|
||||||
'obtain',
|
'obtain',
|
||||||
|
@ -1249,6 +1249,7 @@ export default [
|
||||||
'pair',
|
'pair',
|
||||||
'palace',
|
'palace',
|
||||||
'pale',
|
'pale',
|
||||||
|
'papa',
|
||||||
'paper',
|
'paper',
|
||||||
'paradise',
|
'paradise',
|
||||||
'paragraph',
|
'paragraph',
|
||||||
|
@ -1403,6 +1404,8 @@ export default [
|
||||||
'rage',
|
'rage',
|
||||||
'rain',
|
'rain',
|
||||||
'raise',
|
'raise',
|
||||||
|
'ran',
|
||||||
|
'rang',
|
||||||
'range',
|
'range',
|
||||||
'rank',
|
'rank',
|
||||||
'rapid',
|
'rapid',
|
||||||
|
@ -1582,7 +1585,6 @@ export default [
|
||||||
'sharp',
|
'sharp',
|
||||||
'she',
|
'she',
|
||||||
'sheep',
|
'sheep',
|
||||||
'sheet',
|
|
||||||
'shelter',
|
'shelter',
|
||||||
'ship',
|
'ship',
|
||||||
'shock',
|
'shock',
|
||||||
|
@ -1820,7 +1822,6 @@ export default [
|
||||||
'thereof',
|
'thereof',
|
||||||
'these',
|
'these',
|
||||||
'they',
|
'they',
|
||||||
'they',
|
|
||||||
'thick',
|
'thick',
|
||||||
'thin',
|
'thin',
|
||||||
'thing',
|
'thing',
|
||||||
|
@ -1975,7 +1976,6 @@ export default [
|
||||||
'western',
|
'western',
|
||||||
'wet',
|
'wet',
|
||||||
'what',
|
'what',
|
||||||
'what',
|
|
||||||
'whatever',
|
'whatever',
|
||||||
'whatsoever',
|
'whatsoever',
|
||||||
'wheel',
|
'wheel',
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import small from './2048'
|
module.exports = {
|
||||||
|
small: require('./2048')
|
||||||
console.assert(small.length === 2048)
|
}
|
||||||
|
|
||||||
export default { small }
|
|
||||||
|
|
22
tests/words.js
Normal file
22
tests/words.js
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
const assert = require('assert').strict
|
||||||
|
const words = require('../src/words')
|
||||||
|
|
||||||
|
describe('Word List Tests', () => {
|
||||||
|
const lists = ['small']
|
||||||
|
|
||||||
|
it('length', () => {
|
||||||
|
assert.equal(words.small.length, 2048, 'small list size incorrect')
|
||||||
|
})
|
||||||
|
|
||||||
|
lists.forEach(name => {
|
||||||
|
it(`${name} uniqueness`, () => {
|
||||||
|
const store = {}
|
||||||
|
|
||||||
|
words[name].forEach(word => {
|
||||||
|
const key = `word_${word}`
|
||||||
|
assert(!store[key], `word ${word} is duplicated`)
|
||||||
|
store[key] = true
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in a new issue