# Help needed testing decimal package

**URL:** <https://discuss.ocaml.org/t/help-needed-testing-decimal-package/6772>\
**Category:** Ecosystem\
**Created:** [November 15, 2020, 9:58pm UTC](https://discuss.ocaml.org/t/help-needed-testing-decimal-package/6772 "2020-11-15T21:58:29Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![yawaramin](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/yawaramin/32/3384_2.png) [@yawaramin](https://discuss.ocaml.org/u/yawaramin)\
**Post date:** [November 15, 2020, 9:58pm UTC](https://discuss.ocaml.org/t/help-needed-testing-decimal-package/6772/1 "2020-11-15T21:58:29Z")

</div>

Hi, I’ve been working on a `decimal` package: [https://github.com/yawaramin/ocaml-decimal](https://github.com/yawaramin/ocaml-decimal) (arbitrary-precision floating-point decimals).

I’ve published a _very early preview_ on opam: [http://opam.ocaml.org/packages/decimal/](http://opam.ocaml.org/packages/decimal/)

You can try it out:

```auto
$ opam install decimal
$ utop
#
  #require "decimal";;
#
  module D = Decimal
  let i = D.of_int
  let s = D.of_string;;
#
  #install_printer D.pp;;
#
  D.(s "0.1" + s "0.2");;
- : D.t = 0.3
# (* default precision is 32 *)
  D.(i 1 / i 3);;
- : D.t = 0.33333333333333333333333333333333

```

The module is basically a port of the [Python decimal](https://docs.python.org/3/library/decimal.html) module, with some simplifications like, I’m ignoring different types of NaN like negative NaN, quiet NaN, signalling NaN, and just treating them all as NaN. Otherwise I aim to have the same functionality.

What I need help with mainly is porting the Python `decimal` unit tests: [https://github.com/python/cpython/tree/23831a7a90956e38b7d70304bb6afe30d37936de/Lib/test/decimaltestdata](https://github.com/python/cpython/tree/23831a7a90956e38b7d70304bb6afe30d37936de/Lib/test/decimaltestdata) . They are written in a plain-text DSL consisting of test cases like:

```auto
addx6324 add 0.12 0.01 -> 0.13

```

And I assume they have an interpreter somewhere that parses and runs these tests as standard Python unit tests.

What I would like to do is to port these tests into plain OCaml. The above test case could look like (e.g. Alcotest):

```auto
check string "addx6324" "0.13" D.(to_string (s "0.12" + s "0.01"))

```

The test DSL has a few more features, like comments and setting and checking flags, but not too much more complex. So I would really appreciate some help with porting them. I was thinking good old regular expressions to do the conversions, but I’m open to suggestions.

---

_[View the full topic](https://discuss.ocaml.org/t/help-needed-testing-decimal-package/6772)._
