Skip to content

Instantly share code, notes, and snippets.

@niku
Last active December 23, 2023 12:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niku/3f445fa36d241724f84d2fecae6b5054 to your computer and use it in GitHub Desktop.
Save niku/3f445fa36d241724f84d2fecae6b5054 to your computer and use it in GitHub Desktop.
a sample repository of prop_check with rspec
# コードを gist に保存したい
# gist はフラットなファイル構造しか受けつけない
# ルート直下を探索パスに含めるために必要なオプション
-I .
# ドキュメント形式でテスト結果を示すのに必要なオプション
--format documentation
source "https://rubygems.org"
gem "rspec", "~> 3.12"
gem "prop_check", "~> 0.18.1"
GEM
remote: https://rubygems.org/
specs:
amazing_print (1.5.0)
diff-lcs (1.5.0)
prop_check (0.18.1)
amazing_print (~> 1.2)
rspec (3.12.0)
rspec-core (~> 3.12.0)
rspec-expectations (~> 3.12.0)
rspec-mocks (~> 3.12.0)
rspec-core (3.12.2)
rspec-support (~> 3.12.0)
rspec-expectations (3.12.3)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-support (3.12.1)
PLATFORMS
arm64-darwin-23
DEPENDENCIES
prop_check (~> 0.18.1)
rspec (~> 3.12)
CHECKSUMS
amazing_print (1.5.0) sha256=f9f411b37257333a0f0cc16ce6520b2217a6f0b5a9f35656e1d403cd5e0c3362
diff-lcs (1.5.0) sha256=49b934001c8c6aedb37ba19daec5c634da27b318a7a3c654ae979d6ba1929b67
prop_check (0.18.1) sha256=b1e1d4bf53bbd72f31d889835277ef6edcdfdbf0dc06861cb81107539567ba1d
rspec (3.12.0) sha256=ccc41799a43509dc0be84070e3f0410ac95cbd480ae7b6c245543eb64162399c
rspec-core (3.12.2) sha256=155b54480f28e2b2813185077fe435c2d663031616360ed3b179a9d6a55d2551
rspec-expectations (3.12.3) sha256=093d18e2e7e0a2c619ef8f7343d442fc6c0793fb7897d56f16f26c8a9d244416
rspec-mocks (3.12.6) sha256=de51a4148ba2ce6f1c1646a2a03e9df2f52da9a42b164f2e7467b2cbe37e07bf
rspec-support (3.12.1) sha256=f969b85d0068ff97bc47c9d6fc2bca9706d73406f2b4e5d3b346443d8734c8cf
BUNDLED WITH
2.5.0.dev
# 全ての要素が整数の、要素を 1 つ以上持つ配列を引数にとり、その要素の合計を要素数で割った平均を整数で返す
def naive_average(array)
array.sum / array.length
end
require 'naive_average'
require 'prop_check'
require 'rspec'
RSpec.describe "#naive_average" do
G = PropCheck::Generators
it "returns an integer for any input except empty array" do
PropCheck.forall(G.array(G.integer, empty: false)) do |numbers|
result = naive_average(numbers)
expect(result).to be_a(Integer)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment