Skip to content

Commit

Permalink
Add 'format' npm script; run Prettier on all files
Browse files Browse the repository at this point in the history
  • Loading branch information
caleb531 committed Sep 1, 2024
1 parent 0bd7061 commit f4bcadc
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 81 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: tests

on:
push:
branches: ["*"]
branches: ['*']
pull_request:
branches: ["*"]
branches: ['*']

jobs:
test:
Expand All @@ -31,7 +31,7 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
.env
.env.*
!.env.example
/.aider*

# Ignore files for PNPM, NPM and YARN
pnpm-lock.yaml
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Truthy

*Copyright 2016-2023 Caleb Evans*
*Released under the MIT License*
_Copyright 2016-2023 Caleb Evans_
_Released under the MIT License_

[![tests](https://github.com/caleb531/truthy/actions/workflows/tests.yml/badge.svg)](https://github.com/caleb531/truthy/actions/workflows/tests.yml)
[![Coverage Status](https://coveralls.io/repos/github/caleb531/truthy/badge.svg?branch=main)](https://coveralls.io/github/caleb531/truthy?branch=main)
Expand Down
50 changes: 27 additions & 23 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Truthy | Truth tables made easy | Caleb Evans</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Generate truth tables effortlessly for any number of boolean expressions" />
<meta http-equiv="Content-Security-Policy"
content="default-src 'none'; style-src 'self' data: https://fonts.googleapis.com 'unsafe-inline'; font-src 'self' data: https://fonts.gstatic.com; script-src 'self' https://gc.zgo.at; img-src 'self' data:; connect-src 'self' https://fonts.googleapis.com https://fonts.gstatic.com https://calebevans-projects.goatcounter.com/count; manifest-src 'self'">
<link rel="shortcut icon" href="icons/favicon.png" />
<link rel="apple-touch-icon" href="icons/apple-touch-icon.png" sizes="180x180" />
<script
data-goatcounter="https://calebevans-projects.goatcounter.com/count"
async
src="https://gc.zgo.at/count.v4.js"
crossorigin="anonymous"
integrity="sha384-nRw6qfbWyJha9LhsOtSb2YJDyZdKvvCFh0fJYlkquSFjUxp9FVNugbfy8q1jdxI+"
></script>
</head>
<body>
<head>
<meta charset="UTF-8" />
<title>Truthy | Truth tables made easy | Caleb Evans</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta
name="description"
content="Generate truth tables effortlessly for any number of boolean expressions"
/>
<meta
http-equiv="Content-Security-Policy"
content="default-src 'none'; style-src 'self' data: https://fonts.googleapis.com 'unsafe-inline'; font-src 'self' data: https://fonts.gstatic.com; script-src 'self' https://gc.zgo.at; img-src 'self' data:; connect-src 'self' https://fonts.googleapis.com https://fonts.gstatic.com https://calebevans-projects.goatcounter.com/count; manifest-src 'self'"
/>
<link rel="shortcut icon" href="icons/favicon.png" />
<link rel="apple-touch-icon" href="icons/apple-touch-icon.png" sizes="180x180" />
<script
data-goatcounter="https://calebevans-projects.goatcounter.com/count"
async
src="https://gc.zgo.at/count.v4.js"
crossorigin="anonymous"
integrity="sha384-nRw6qfbWyJha9LhsOtSb2YJDyZdKvvCFh0fJYlkquSFjUxp9FVNugbfy8q1jdxI+"
></script>
</head>
<body>
<main></main>

<main></main>

<script type="module" src="scripts/index.js"></script>
</body>
<script type="module" src="scripts/index.js"></script>
</body>
</html>
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"dev": "vite",
"build": "vite build",
"preview": "vite preview",
"lint": "eslint",
"lint": "prettier --check . && eslint .",
"format": "prettier --write .",
"test": "vitest run",
"coverage": "vitest run --coverage"
},
Expand Down
2 changes: 0 additions & 2 deletions test/app.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import App from '../scripts/models/app.js';

describe('app', () => {

it('should initialize with no arguments', () => {
let app = new App();
expect(app).toHaveProperty('variables');
Expand Down Expand Up @@ -58,5 +57,4 @@ describe('app', () => {
expect(restoredApp).toBeTruthy();
expect(restoredApp.serialize()).toEqual(serializedApp);
});

});
7 changes: 2 additions & 5 deletions test/collection.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import Collection from '../scripts/models/collection.js';

describe('collection', () => {

class DummyItem {
constructor(args) {
this.foo = args.foo;

}
serialize() {
return { foo: this.foo };
Expand All @@ -27,8 +25,8 @@ describe('collection', () => {
it('should serialize to a JSON object', () => {
let serializedCollection = { items: [{ foo: 'abc' }, { foo: 'xyz' }] };
let collection = new Collection({
SubCollectionItem: DummyItem,
items: serializedCollection.items
SubCollectionItem: DummyItem,
items: serializedCollection.items
});
expect(collection.serialize()).toEqual(serializedCollection);
});
Expand Down Expand Up @@ -117,5 +115,4 @@ describe('collection', () => {
expect(collection.length).toEqual(0);
expect(collection.items.length).toEqual(0);
});

});
2 changes: 0 additions & 2 deletions test/expression-collection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ExpressionCollection from '../scripts/models/expression-collection.js';
import Expression from '../scripts/models/expression.js';

describe('expression collection', () => {

it('should initialize with list of expressions', () => {
let expressions = new ExpressionCollection({
items: [{ string: 'a xor b' }, { string: 's nand t' }]
Expand All @@ -13,5 +12,4 @@ describe('expression collection', () => {
expect(expression).toBeInstanceOf(Expression);
});
});

});
47 changes: 12 additions & 35 deletions test/expression.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Expression from '../scripts/models/expression.js';

describe('expression', () => {

it('should initialize with unmodified input string', () => {
let expression = new Expression({
string: ' p and q '
Expand All @@ -25,25 +24,29 @@ describe('expression', () => {
const testResults = testCases.map((testCase) => {
let actualOutput = expression.evaluate(testCase.varValues);
// String of current variable values for display in fail message
let varValuesStr = Object.entries(testCase.varValues).map(([varName, varValue]) => {
return varName + ' is ' + varValue;
}).join(' and ');
const message = () => `expected '${expressionStr}' to evaluate to ${testCase.output} but got ${actualOutput} (when ${varValuesStr})`;
let varValuesStr = Object.entries(testCase.varValues)
.map(([varName, varValue]) => {
return varName + ' is ' + varValue;
})
.join(' and ');
const message = () =>
`expected '${expressionStr}' to evaluate to ${testCase.output} but got ${actualOutput} (when ${varValuesStr})`;
if (actualOutput === testCase.output) {
return { message, pass: true };
} else {
return { message, pass: false };
}
});

return testResults.find((result) => {
return !result.pass;
}) || testResults[testResults.length - 1];
return (
testResults.find((result) => {
return !result.pass;
}) || testResults[testResults.length - 1]
);
}
});

describe('variable name', () => {

it('should evaluate', () => {
expect('p').toEvaluateTo([
{ varValues: { p: false }, output: false },
Expand Down Expand Up @@ -79,13 +82,10 @@ describe('expression', () => {
{ varValues: { p: true }, output: null }
]);
});

});

describe('boolean value', () => {

describe('false', () => {

let testCases = [
{ varValues: { p: false }, output: false },
{ varValues: { p: true }, output: false }
Expand All @@ -98,11 +98,9 @@ describe('expression', () => {
it('should be case-insensitive', () => {
expect('FaLsE').toEvaluateTo(testCases);
});

});

describe('true', () => {

let testCases = [
{ varValues: { p: false }, output: true },
{ varValues: { p: true }, output: true }
Expand All @@ -115,13 +113,10 @@ describe('expression', () => {
it('should be case-insensitive', () => {
expect('tRuE').toEvaluateTo(testCases);
});

});

});

describe('NOT operation', () => {

let testCases = [
{ varValues: { p: false }, output: true },
{ varValues: { p: true }, output: false }
Expand Down Expand Up @@ -153,11 +148,9 @@ describe('expression', () => {
{ varValues: { p: true }, output: null }
]);
});

});

describe('AND operation', () => {

let testCases = [
{ varValues: { p: false, q: false }, output: false },
{ varValues: { p: false, q: true }, output: false },
Expand Down Expand Up @@ -200,11 +193,9 @@ describe('expression', () => {
it('should ignore whitespace around arithmetic operator', () => {
expect('p * q').toEvaluateTo(testCases);
});

});

describe('NAND operation', () => {

let testCases = [
{ varValues: { p: false, q: false }, output: true },
{ varValues: { p: false, q: true }, output: true },
Expand All @@ -223,11 +214,9 @@ describe('expression', () => {
it('should ignore operator case', () => {
expect('p NanD q').toEvaluateTo(testCases);
});

});

describe('OR operation', () => {

let testCases = [
{ varValues: { p: false, q: false }, output: false },
{ varValues: { p: false, q: true }, output: true },
Expand Down Expand Up @@ -270,11 +259,9 @@ describe('expression', () => {
it('should ignore whitespace around arithmetic operator', () => {
expect('p + q').toEvaluateTo(testCases);
});

});

describe('NOR operation', () => {

let testCases = [
{ varValues: { p: false, q: false }, output: true },
{ varValues: { p: false, q: true }, output: false },
Expand All @@ -293,11 +280,9 @@ describe('expression', () => {
it('should ignore operator case', () => {
expect('p NoR q').toEvaluateTo(testCases);
});

});

describe('XOR operation', () => {

let testCases = [
{ varValues: { p: false, q: false }, output: false },
{ varValues: { p: false, q: true }, output: true },
Expand All @@ -324,11 +309,9 @@ describe('expression', () => {
it('should ignore whitespace around shorthand operator', () => {
expect('p ^ q').toEvaluateTo(testCases);
});

});

describe('implication operation', () => {

let testCases = [
{ varValues: { p: false, q: false }, output: true },
{ varValues: { p: false, q: true }, output: true },
Expand All @@ -343,11 +326,9 @@ describe('expression', () => {
it('should ignore whitespace around operator', () => {
expect('p -> q').toEvaluateTo(testCases);
});

});

describe('double-implication (XNOR) operation', () => {

let testCases = [
{ varValues: { p: false, q: false }, output: true },
{ varValues: { p: false, q: true }, output: false },
Expand All @@ -374,7 +355,6 @@ describe('expression', () => {
it('should ignore named operator case', () => {
expect('p xNoR q').toEvaluateTo(testCases);
});

});

it('should respect parentheses', () => {
Expand Down Expand Up @@ -405,7 +385,6 @@ describe('expression', () => {
});

describe('more than two variables', () => {

let testCases = [
{ varValues: { p: false, q: false, r: false }, output: false },
{ varValues: { p: false, q: false, r: true }, output: true },
Expand All @@ -420,7 +399,5 @@ describe('expression', () => {
it('should evaluate named operator', () => {
expect('p xor q xor r').toEvaluateTo(testCases);
});

});

});
2 changes: 0 additions & 2 deletions test/ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import m from 'mithril';
import AppComponent from '../scripts/components/app.jsx';

describe('app UI', () => {

beforeEach(() => {
localStorage.clear();
document.body.appendChild(document.createElement('main'));
Expand Down Expand Up @@ -227,5 +226,4 @@ describe('app UI', () => {
let expression = document.querySelector('.expression:last-child input');
expect(expression).toHaveValue('a ^ b');
});

});
4 changes: 0 additions & 4 deletions test/variable-collection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import VariableCollection from '../scripts/models/variable-collection.js';
import Variable from '../scripts/models/variable.js';

describe('variable collection', () => {

it('should initialize with list of variables', () => {
let variables = new VariableCollection({
items: [{ name: 'u' }, { name: 'v' }]
Expand Down Expand Up @@ -34,7 +33,6 @@ describe('variable collection', () => {
});

describe('getNextVariableName', () => {

let variables = new VariableCollection({
items: [{ name: 'q' }, { name: 's' }, { name: 'z' }, { name: 'a' }]
});
Expand All @@ -48,7 +46,5 @@ describe('variable collection', () => {
it('should wrap around to next available name as needed', () => {
expect(variables.getNextVariableName(variables.items[2])).toEqual('b');
});

});

});
Loading

0 comments on commit f4bcadc

Please sign in to comment.