www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Hypothesis equivalent for D?

reply James Lu <jamtlu gmail.com> writes:
Hypothesis is a Python library for generating tests. 
https://hypothesis.readthedocs.io/en/latest/quickstart.html

from hypothesis import example, given, strategies as st


 given(st.text())
 example("")
def test_decode_inverts_encode(s):
     assert decode(encode(s)) == s

What are the equivalent D libraries?
Apr 10
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 4/10/21 11:47 AM, James Lu wrote:
 Hypothesis is a Python library for generating tests. 
 https://hypothesis.readthedocs.io/en/latest/quickstart.html
 
 from hypothesis import example, given, strategies as st
 
 
  given(st.text())
  example("")
 def test_decode_inverts_encode(s):
     assert decode(encode(s)) == s
 
 What are the equivalent D libraries?
Nice idea, thanks for sharing. I don't think there's a D equivalent, and there's a need because there definitely are some instances of ad-hoc solutions in Phobos unittesting. Defining a systematic library for that stuff would be pretty awesome and would cut down a lot of duplication from Phobos.
Apr 10
next sibling parent James Lu <jamtlu gmail.com> writes:
On Saturday, 10 April 2021 at 16:57:04 UTC, Andrei Alexandrescu 
wrote:
 Defining a systematic library for that stuff would be pretty 
 awesome and would cut down a lot of duplication from Phobos.
In Python, hypothesis is used with icontract, a Design-by-Contract library. Generated testcases are discarded if they don't meet the contract. icontract-hypothesis also has a mode that automatically infers hypothesis testcase generation strategy such that it always satisfies the contract. (!) https://pypi.org/project/icontract-hypothesis/
Apr 12
prev sibling parent reply Robert burner Schadek <rburners gmail.com> writes:
 What are the equivalent D libraries?
Nice idea, thanks for sharing. I don't think there's a D equivalent,
Property-based testing in unit-threaded which was based on https://code.dlang.org/packages/std_benchmark
Apr 12
parent Atila Neves <atila.neves gmail.com> writes:
On Tuesday, 13 April 2021 at 06:38:59 UTC, Robert burner Schadek 
wrote:
 What are the equivalent D libraries?
Nice idea, thanks for sharing. I don't think there's a D equivalent,
Property-based testing in unit-threaded which was based on https://code.dlang.org/packages/std_benchmark
Yep, here: https://github.com/atilaneves/unit-threaded/blob/cfdca0af7e40458bec66cfa7e959d4726496be7f/subpackages/property/source/unit_threaded/property.d#L173
Apr 16