Skip to content

pmcelhaney/boolio

Repository files navigation

Boolio

Boolio is a little app that will take a boolean expression

(isRaining && !has("umbrella")) ||
  (!isRaining && temperature < 50 && (age < 7 || age > 18));

and turn it into a truth table.

isRaininghas("umbrella")temperature < 50age < 7age > 18=
TTTTTF
TTTTFF
TTTFTF
TTTFFF
TTFTTF
TTFTFF
TTFFTF
TTFFFF
TFTTTT
TFTTFT
TFTFTT
TFTFFT
TFFTTT
TFFTFT
TFFFTT
TFFFFT
FTTTTT
FTTTFT
FTTFTT
FTTFFF
FTFTTF
FTFTFF
FTFFTF
FTFFFF
FFTTTT
FFTTFT
FFTFTT
FFTFFF
FFFTTF
FFFTFF
FFFFTF
FFFFFF

You will* then be able to inspect the truth table, fix any results that are wrong, and automatically update the boolean expression to match the truth table.

It will* also simplify the expression (if possible), using the Quine-McCluskly algorithm and provide a head start on filling in missing tests.

function myFunction(a,b,c,d,e) {
    return isRaining && !has("umbrella") || (!isRaining && temperature < 50 && (age < 7 || age > 18));
}

expect.each([
      [ true, true, true, true, true, false ],
      [ true, true, true, true, false, false ],
      [ true, true, true, false, true, false ],
      [ true, true, true, false, false, false ],
      [ true, true, false, true, true, false ],
      [ true, true, false, true, false, false ],
      [ true, true, false, false, true, false ],
      [ true, true, false, false, false, false ],
      [ true, false, true, true, true, true ],
      [ true, false, true, true, false, true ],
      [ true, false, true, false, true, true ],
      [ true, false, true, false, false, true ],
      [ true, false, false, true, true, true ],
      [ true, false, false, true, false, true ],
      [ true, false, false, false, true, true ],
      [ true, false, false, false, false, true ],
      [ false, true, true, true, true, true ],
      [ false, true, true, true, false, true ],
      [ false, true, true, false, true, true ],
      [ false, true, true, false, false, false ],
      [ false, true, false, true, true, false ],
      [ false, true, false, true, false, false ],
      [ false, true, false, false, true, false ],
      [ false, true, false, false, false, false ],
      [ false, false, true, true, true, true ],
      [ false, false, true, true, false, true ],
      [ false, false, true, false, true, true ],
      [ false, false, true, false, false, false ],
      [ false, false, false, true, true, false ],
      [ false, false, false, true, false, false ],
      [ false, false, false, false, true, false ],
      [ false, false, false, false, false, false ]
    ], `Given isRaining === %s, has('umbrella') === %s, temperature < 50 === %s, age < 7 === %s, and age > 18 === %s, result is %s`)(a, b, c, d, e, result) {
    expect(myFunction(a, b, c, d, e)).toEqual(result);
}

The first iteration will work with JavaScript. Support for other languages and unit test frameworks will follow.

This is mostly just for fun. I dunno, maybe it will lead to something useful.

* Not implmeted yet

About

Boolean expression assistant

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published