def test_scale_places_neg(size): scaled_by_string = get_test_value(size, -size) dec_value = get_test_value(size, 0) scaled_by_math = scale_places(-size)(dec_value) assert scaled_by_string == scaled_by_math
def get_ufixed_strategy(abi_type: ABIType, registry: StrategyRegistry) -> st.SearchStrategy: bits, places = abi_type.sub return st.decimals( min_value=0, max_value=2 ** bits - 1, places=0, ).map(scale_places(places))
)) int_total_bits = st.shared(total_bits, key='int_total_bits') int_strs = int_total_bits.map('int{}'.format) int_values = int_total_bits.flatmap(lambda n: st.integers( min_value=-2**(n - 1), max_value=2**(n - 1) - 1, )) ufixed_size_tuples = st.shared(fixed_sizes, key='ufixed_size_tuples') ufixed_strs = ufixed_size_tuples.map(join_with_x).map('ufixed{}'.format) ufixed_values = ufixed_size_tuples.flatmap(lambda sz: st.decimals( min_value=0, max_value=2**sz[0] - 1, places=0, ).map(scale_places(sz[1]))) fixed_size_tuples = st.shared(fixed_sizes, key='fixed_size_tuples') fixed_strs = fixed_size_tuples.map(join_with_x).map('fixed{}'.format) fixed_values = fixed_size_tuples.flatmap(lambda sz: st.decimals( min_value=-2**(sz[0] - 1), max_value=2**(sz[0] - 1) - 1, places=0, ).map(scale_places(sz[1]))) fixed_bytes_sizes = st.shared(bytes_sizes, key='fixed_bytes_sizes') fixed_bytes_strs = fixed_bytes_sizes.map('bytes{}'.format) fixed_bytes_values = fixed_bytes_sizes.flatmap(lambda n: st.binary( min_size=n, max_size=n, ))
def test_scale_places_raises_value_error_if_places_not_int(): with pytest.raises(ValueError): scale_places(1.0)