Skip to content

add property tests for fast division routines - #46

Merged
harendra-kumar merged 2 commits into
masterfrom
test-division
Jul 24, 2020
Merged

harendra-kumar merged 2 commits into
masterfrom
test-division

Conversation

@harendra-kumar

Copy link
Copy Markdown
Member

No description provided.

@harendra-kumar
harendra-kumar requested a review from Bodigrim May 16, 2020 05:57
Comment thread unicode-transforms.cabal
Data.ByteString.UTF8.Normalize
Data.Text.Normalize
Data.Unicode.Types
Data.Unicode.Internal.Division

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm reluctant to expose this module. Could we possibly use an internal library for it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earlier I was of the view to not expose Internal modules. But I have stopped caring about it now. It just became a hassle, and we also had some trouble with internal libraries. So in streamly now we have just exposed everything. If you care about it, you can give a try to the internal library.

Comment thread test/Properties.hs Outdated
putStrLn "quotRem28"
check $ \n -> n `quotRem` 28 == quotRem28 n
putStrLn "quotRem21"
check $ \n -> n `quotRem` 21 == quotRem21 n

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Strictly speaking, quotRem21 and quotRem28 are valid only for non-negative inputs, I'm a bit surprised that they pass as is.
  • It is important to check the upper end of range as well, like check $ \n -> quotRem (maxBound - n) 21 == quotRem 21 (maxBound - n).

@harendra-kumar harendra-kumar May 17, 2020 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests were indeed failing, but the result was showing as passed, I fixed that.

The division works correctly upto maxBound / 2, fails beyond that.

Comment thread test/Properties.hs Outdated
(fromIntegral n) `quotRem` 21 == quotRem21 (fromIntegral n)
prop "quotRem21 maxBound" $ \(n :: Word) ->
let n1 = maxBound `div` 2 - n
in (fromIntegral n1) `quotRem` 21 == quotRem21 (fromIntegral n1)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could look simpler with NonNegative wrapper:

import Test.QuickCheck (NonNegative(..))
...
        prop "quotRem28" $ \(NonNegative n) -> n `quotRem` 28 == quotRem28 n
        prop "quotRem28 maxBound" $ \(NonNegative n') ->
            let n = maxBound - n' in n `quotRem` 28 == quotRem28 n
        prop "quotRem21" $ \(NonNegative n) -> n `quotRem` 21 == quotRem21 n
        prop "quotRem21 maxBound" $ \(NonNegative n') ->
            let n = maxBound - n' in n `quotRem` 21 == quotRem21 n

@harendra-kumar

Copy link
Copy Markdown
Member Author

@Bodigrim I made the fixes as suggested by you. I also made an internal library for testing instead of exposing the internal module. Let me know if this looks good.

@harendra-kumar

Copy link
Copy Markdown
Member Author

The coverage build is not working due to internal library. This may be one of the reasons why we did not use internal libraries earlier:

cabal --project-file=../../cabal.project.coveralls v2-build --enable-tests --enable-benchmarks --enable-coverage all

HEAD is now at d9e2017 Bump package version to 1.1.0.

Resolving dependencies...

Error:

    Internal libraries only supported with per-component builds.

    Per-component builds were disabled because program coverage is enabled

    In the inplace package 'unicode-transforms-0.3.6'

@harendra-kumar

Copy link
Copy Markdown
Member Author

I tried a hack to symlink only the internal module that we are trying to test for using in the tests. I could not find a better way to do this without exposing the module.

I tried pulling the module into the test executable right from its current location without symlinking it into a separate directory but that does not work because cabal then starts picking up all the modules in the Data directory directly and not via the unicode-transforms library.

Let me know if there is a better way to do this which does not require disabling coverage.

@harendra-kumar

Copy link
Copy Markdown
Member Author

Ah, symlinks do not work on Windows. So there seems to be no way.

@Bodigrim

Copy link
Copy Markdown
Collaborator

Maybe add {-# OPTIONS_HADDOCK hide #-} to Data.Unicode.Internal.Division? Technically it will remain available, but no haddock documentation should hopefully discourage its use.

@harendra-kumar

Copy link
Copy Markdown
Member Author

Ok, I have exposed the module and hidden the haddock.

@Bodigrim

Copy link
Copy Markdown
Collaborator

@harendra-kumar

Copy link
Copy Markdown
Member Author

The test passes on my machine which has libicu65 installed:

Prelude Main> import qualified Data.Text.ICU as ICU  
Prelude Main ICU> import qualified Data.Text.Normalize as T
Prelude Main ICU T> import qualified Data.Text as Text
Prelude Main ICU T Text> T.normalize T.NFKD (Text.pack "\127340") == ICU.normalize ICU.NFKD (Text.pack "\127340")
True

The travis test is using libicu55 from Ubuntu xenial. We can try if libicu55 reproduces this error then we can perhaps say its because of old icu lib. If we cannot reproduce with that then something weird is going on.

@harendra-kumar

Copy link
Copy Markdown
Member Author

We can also try using Ubuntu bionic in the CI tests, we will have to find a way to install icu on bionic.

@harendra-kumar

Copy link
Copy Markdown
Member Author

It seems codepoint 1f16c (\127340) was introduced in unicode version 12 (https://www.unicode.org/Public/12.0.0/ucd/UnicodeData.txt) and icu55 is at unicode version 7. We need to use the right version of icu i.e. a version that supports unicode version 13.

@Bodigrim

Copy link
Copy Markdown
Collaborator

I see. As long as we know that it is an obsolete ICU who is wrong and not unicode-transforms, I think we can go ahead with a merge.

@harendra-kumar

Copy link
Copy Markdown
Member Author

We need minimum icu-64 to avoid this issue. I will check where to get it from and how to install it on travis.

This also raises another important question: should we bump the major version of unicode-transforms whenever we add support for a new version of Unicode? Though unicode is upward compatible so I guess there should not be any issues, but I am not very sure as I am not an expert.

@harendra-kumar

Copy link
Copy Markdown
Member Author

ICU official page redirects to its github release page: https://github.com/unicode-org/icu/releases/tag/release-67-1 where I can find a tgz for ubuntu, if we want to install this we may also have to install the icu data package separately. Not sure how easy would it be to work with this.

ubuntu focal seems to have icu66 we can try that: https://packages.ubuntu.com/focal/libicu66

@Bodigrim

Copy link
Copy Markdown
Collaborator

@Bodigrim

Copy link
Copy Markdown
Collaborator

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants