···11-import toDecimal from './to-decimal';
22-33-describe('toDecimal', () => {
44- test('Should convert A to 1', () => {
55- expect(toDecimal('A')).toBe(1);
66- });
77-88- test('Should convert B to 2', () => {
99- expect(toDecimal('B')).toBe(2);
1010- });
1111-1212- test('Should convert Z to 26', () => {
1313- expect(toDecimal('Z')).toBe(26);
1414- });
1515-1616- test('Should convert AA to 27', () => {
1717- expect(toDecimal('AA')).toBe(27);
1818- });
1919-2020- test('Should convert AB to 28', () => {
2121- expect(toDecimal('AB')).toBe(28);
2222- });
2323-2424- test('Should convert AC to 29', () => {
2525- expect(toDecimal('AC')).toBe(29);
2626- });
2727-2828- test('Should throw if given a non-upper-case character', () => {
2929- expect(() => {
3030- toDecimal('a');
3131- }).toThrow();
3232- });
3333-});
+27
test/increment.ts
···11+import test from 'ava';
22+import increment from '../source/increment';
33+44+type TestCase = {
55+ from: string;
66+ to: string;
77+};
88+99+const testCases: TestCase[] = [
1010+ {from: 'A', to: 'B'},
1111+ {from: 'Z', to: 'AA'},
1212+ {from: 'ZZ', to: 'AAA'},
1313+ {from: 'AA', to: 'AB'},
1414+ {from: 'AB', to: 'AC'},
1515+ {from: 'AAA', to: 'AAB'},
1616+ {from: 'AAB', to: 'AAC'}
1717+];
1818+1919+for (const {from, to} of testCases) {
2020+ test(`increments ${from} to ${to}`, (t) => {
2121+ t.is(increment(from), to);
2222+ });
2323+}
2424+2525+test('throws if passed non-bijective base-26 string', (t) => {
2626+ t.throws(() => increment('abc123'));
2727+});
+18
test/random.ts
···11+import test from 'ava';
22+import {random, range} from '../source';
33+44+test('returns a valid string given only an upper bound', (t) => {
55+ const validLetters = range('AAA');
66+77+ for (let i = 0; i < 1000; ++i) {
88+ t.assert(validLetters.includes(random('ZZ')));
99+ }
1010+});
1111+1212+test('returns a valid string given both upper and lower bounds', (t) => {
1313+ const validLetters = range('AA', 'AAA');
1414+1515+ for (let i = 0; i < 1000; ++i) {
1616+ t.assert(validLetters.includes(random('AA', 'ZZ')));
1717+ }
1818+});
+19
test/range.ts
···11+import test from 'ava';
22+import range from '../source/range';
33+44+test('works with end', (t) => {
55+ t.deepEqual(range('A'), []);
66+ t.deepEqual(range('B'), ['A']);
77+ t.deepEqual(range('C'), ['A', 'B']);
88+ t.assert(range('AB').includes('AA'));
99+});
1010+1111+test('works with start and end', (t) => {
1212+ t.deepEqual(range('B', 'C'), ['B']);
1313+ t.deepEqual(range('B', 'D'), ['B', 'C']);
1414+ t.deepEqual(range('ZZ', 'AAC'), ['ZZ', 'AAA', 'AAB']);
1515+});
1616+1717+test('throws if given a string with a non-upper-case letter', (t) => {
1818+ t.throws(() => range('a'));
1919+});
+22
test/to-bb26.ts
···11+import test from 'ava';
22+import toBb26 from '../source/to-bb26';
33+44+type TestCase = {
55+ from: number;
66+ to: string;
77+};
88+99+const testCases: TestCase[] = [
1010+ {from: 1, to: 'A'},
1111+ {from: 2, to: 'B'},
1212+ {from: 26, to: 'Z'},
1313+ {from: 27, to: 'AA'},
1414+ {from: 28, to: 'AB'},
1515+ {from: 29, to: 'AC'}
1616+];
1717+1818+for (const {from, to} of testCases) {
1919+ test(`converts ${from} to ${to}`, (t) => {
2020+ t.is(toBb26(from), to);
2121+ });
2222+}
+26
test/to-decimal.ts
···11+import test from 'ava';
22+import toDecimal from '../source/to-decimal';
33+44+type TestCase = {
55+ from: string;
66+ to: number;
77+};
88+99+const testCases: TestCase[] = [
1010+ {from: 'A', to: 1},
1111+ {from: 'B', to: 2},
1212+ {from: 'Z', to: 26},
1313+ {from: 'AA', to: 27},
1414+ {from: 'AB', to: 28},
1515+ {from: 'AC', to: 29}
1616+];
1717+1818+for (const {from, to} of testCases) {
1919+ test(`converts ${from} to ${to}`, (t) => {
2020+ t.is(toDecimal(from), to);
2121+ });
2222+}
2323+2424+test('throws for non-upper-case character', (t) => {
2525+ t.throws(() => toDecimal('a'));
2626+});