bidi: port of reference implementation

Also added tests.

Notes:
1) To run tests, run "go test --long". At some point I can perhaps
generate (a sample of) tests, but that would be for a different CL.
The total size of the test files is about 13M.

2) All reordering tests pass. Some of the level tests fail in esoteric
cases, although the results look fine. A failing level test is not so
important as long as the reodering result is identical, so I made
these tests optional. (Note only about 150 out of 1M+ tests have
different but possibly correct levels.)

3) This implementation is far from optimized. The main goal was to
get the port working and the tests to pass.

Change-Id: Ib137e9263e6af1f0c11e78c5a68747250a4bc378
Reviewed-on: https://go-review.googlesource.com/17296
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
3 files changed