File: basic_examples_spec.rb

package info (click to toggle)
python-hypothesis 6.138.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,272 kB
  • sloc: python: 62,853; ruby: 1,107; sh: 253; makefile: 41; javascript: 6
file content (51 lines) | stat: -rw-r--r-- 1,060 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true

def expect_failure(&block)
  expect(&block).to raise_exception(RSpec::Expectations::ExpectationNotMetError)
end

RSpec.describe 'basic hypothesis tests' do
  they 'think integer addition is commutative' do
    hypothesis do
      x = any integers
      y = any integers
      expect(x + y).to eq(y + x)
    end
  end

  they 'are able to find zero values' do
    expect_failure do
      hypothesis do
        x = any integers
        expect(x).not_to eq(0)
      end
    end
  end

  they 'are able to filter out values' do
    hypothesis do
      x = any integers
      assume x != 0
      1 / x
    end
  end

  they 'find that string addition is not commutative' do
    expect_failure do
      hypothesis do
        x = any strings
        y = any strings
        expect(x + y).to be == y + x
      end
    end
  end

  they 'raise unsatisfiable when all assumptions fail' do
    expect do
      hypothesis do
        any integers
        assume false
      end
    end.to raise_exception(Hypothesis::Unsatisfiable)
  end
end