Alpha Chen 2 years ago
parent 59dbb8262b
commit 15ee18083a
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -6,7 +6,12 @@ PATH
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
coderay (1.1.3)
method_source (1.0.0)
minitest (5.16.3) minitest (5.16.3)
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
rake (13.0.6) rake (13.0.6)
PLATFORMS PLATFORMS
@ -16,6 +21,7 @@ DEPENDENCIES
bundler (~> 2.3) bundler (~> 2.3)
minitest (~> 5.16) minitest (~> 5.16)
minitest-thesis! minitest-thesis!
pry (~> 0.14)
rake (~> 13.0) rake (~> 13.0)
BUNDLED WITH BUNDLED WITH

@ -104,7 +104,7 @@ module Minitest
def just(value) = Possibility.new("just(#{value})") { value } def just(value) = Possibility.new("just(#{value})") { value }
# No possible values. i.e. Any call to `any` will reject the test case. # No possible values. i.e. Any call to `any` will reject the test case.
def nothing = Possibility.new {|tc| tc.reject } def nothing = Possibility.new("nothing") {|tc| tc.reject }
# Possible values can be any value possible for one of `possibilities`. # Possible values can be any value possible for one of `possibilities`.
def mix_of(*possibilities) def mix_of(*possibilities)

@ -5,7 +5,7 @@ module Minitest::Thesis
class Possibility class Possibility
attr_reader :produce, :name attr_reader :produce, :name
def initialize(name = "TODO", &produce) def initialize(name, &produce)
@name = name @name = name
@produce = produce @produce = produce
end end
@ -15,20 +15,20 @@ module Minitest::Thesis
# "Returns a `Possibility` where values come from applying `f` to some possible value for `self`." # "Returns a `Possibility` where values come from applying `f` to some possible value for `self`."
def map(&f) def map(&f)
self.class.new("#{name}.map(TODO)") {|tc| f.call(tc.any(self)) } self.class.new("#{name}.map(#{f.class})") {|tc| f.call(tc.any(self)) }
end end
# Returns a `Possibility` where values come from applying `f` (which # Returns a `Possibility` where values come from applying `f` (which
# should return a new `Possibility` to some possible value for `self` # should return a new `Possibility` to some possible value for `self`
# then returning a possible value from that. # then returning a possible value from that.
def bind(&f) def bind(&f)
self.class.new("#{name}.bind(TODO)") {|tc| tc.any(f.(tc.any(self))) } self.class.new("#{name}.bind(#{f.class})") {|tc| tc.any(f.(tc.any(self))) }
end end
# Returns a `Possibility` whose values are any possible value of `self` # Returns a `Possibility` whose values are any possible value of `self`
# for which `f` returns True. # for which `f` returns True.
def satisfying(&f) def satisfying(&f)
self.class.new("#{name}.select(TODO)") {|test_case| self.class.new("#{name}.select(#{f.class})") {|test_case|
3.times.first { 3.times.first {
candidate = test_case.any(self) candidate = test_case.any(self)
candidate if f.(candidate) candidate if f.(candidate)

@ -38,4 +38,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "bundler", "~> 2.3" spec.add_development_dependency "bundler", "~> 2.3"
spec.add_development_dependency "rake", "~> 13.0" spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "minitest", "~> 5.16" spec.add_development_dependency "minitest", "~> 5.16"
spec.add_development_dependency "pry", "~> 0.14"
end end

Loading…
Cancel
Save