A complex number library for Elm. Someone needed to write one.
I've found that testing numeric computations in elm can be a little bit annoying. Just testing a few critical values is not good enough so you need to randomly generate values and you need to compute the correct values from those values. This could be done with native, but that is rather annoying. Instead, I decided to have python to calculate a bunch of correct values from some randomly generated complex numbers and then write the test code from that. How I do this can be seen in testgen.py, which is not yet documented.
Minor changes to Complex.elm for elm ver 0.18.0
Major changes to tests to use elm-community/elm-test ver 0.18.9
Tests have been split into separate files to avoid stack overflow. testgen-0.18.py creates a suite of 15 test files, each containing 200 randomly generated tests for a specific function of the library.
Tests now use relative tolerance. See Guide to Floating Point Comarison for the rationale. All tests pass within a relative tolerance of 0.0000000000001.
You must install elm-test to use the new tests. To install, do:
$ npm install -g elm-test
To run tests, do:
$ cd tests && make
This will generate the test files if necessary and then run them in sequence. Each testfile contains 200 random tests for a primary library function. A given testfile uses additional functions from the library to test a primary function thereby providing good test coverage.
You can optionally run a single testfile. Example:
$ elm-test tests/Abs.elm
You can generate a new set of testfiles thus:
$ cd tests && make clean && make
Testfiles created are:
Abs.elm Acos.elm Arg.elm Asin.elm Atan.elm Cos.elm Div.elm Exp.elm Ln.elm Mult.elm Pow.elm Sign.elm Sin.elm Sqrt.elm Tan.elm
complex, i, one, zero, fromReal
real, imaginary, abs, conjugate, negation, sgn, arg, sqrt
add, sub, mult, div
sin, cos, tan, asin, acos, atan, euler
ln, exp, pow
Teodoro Fields Collin email original author
Kevin Butler email port to elm 0.17.0
Ryman github port to elm 0.17.0