| 1 |
# This file is part of Hypothesis, which may be found at |
| 2 |
# https://github.com/HypothesisWorks/hypothesis/ |
| 3 |
# |
| 4 |
# Copyright the Hypothesis Authors. |
| 5 |
# Individual contributors are listed in AUTHORS.rst and the git log. |
| 6 |
# |
| 7 |
# This Source Code Form is subject to the terms of the Mozilla Public License, |
| 8 |
# v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 9 |
# obtain one at https://mozilla.org/MPL/2.0/. |
| 10 |
|
| 11 |
import pytest |
| 12 |
|
| 13 |
from hypothesis import assume, given, strategies as st |
| 14 |
from hypothesis.internal.conjecture.junkdrawer import IntList |
| 15 |
|
| 16 |
non_neg_lists = st.lists(st.integers(min_value=0, max_value=2**63 - 1)) |
| 17 |
|
| 18 |
|
| 19 |
@given(non_neg_lists) |
| 20 |
def test_intlist_is_equal_to_itself(ls): |
| 21 |
assert IntList(ls) == IntList(ls) |
| 22 |
|
| 23 |
|
| 24 |
@given(non_neg_lists, non_neg_lists) |
| 25 |
def test_distinct_int_lists_are_not_equal(x, y): |
| 26 |
assume(x != y) |
| 27 |
assert IntList(x) != IntList(y) |
| 28 |
|
| 29 |
|
| 30 |
def test_basic_equality(): |
| 31 |
x = IntList([1, 2, 3]) |
| 32 |
assert x == x |
| 33 |
t = x != x |
| 34 |
assert not t |
| 35 |
assert x != "foo" |
| 36 |
|
| 37 |
s = x == "foo" |
| 38 |
assert not s |
| 39 |
|
| 40 |
|
| 41 |
def test_error_on_invalid_value(): |
| 42 |
with pytest.raises(ValueError): |
| 43 |
IntList([-1]) |
| 44 |
|
| 45 |
|
| 46 |
def test_extend_by_too_large(): |
| 47 |
x = IntList() |
| 48 |
ls = [1, 10**6] |
| 49 |
x.extend(ls) |
| 50 |
assert list(x) == ls |