Skip to content

Commit 8aaf3aa

Browse files
Svetixbotraulraja
authored andcommitted
Update Grouping Properties exersize to accept 3 arguments (#17)
1 parent c27948e commit 8aaf3aa

File tree

3 files changed

+18
-42
lines changed

3 files changed

+18
-42
lines changed

src/main/scala/scalachecklib/PropertiesHelpers.scala

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/main/scala/scalachecklib/PropertiesSection.scala

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ import org.scalatest.prop.Checkers
5151
*/
5252
object PropertiesSection extends Checkers with Matchers with org.scalaexercises.definitions.Section {
5353

54-
import PropertiesHelpers._
55-
5654
/** ==Universally quantified properties==
5755
*
5856
* As mentioned before, `org.scalacheck.Prop.forAll` creates universally quantified properties.
@@ -177,33 +175,30 @@ object PropertiesSection extends Checkers with Matchers with org.scalaexercises.
177175
*
178176
* Often you want to specify several related properties, perhaps for all methods in a class.
179177
* ScalaCheck provides a simple way of doing this, through the `Properties` trait.
180-
* Look at the following specifications that define some properties for zero:
181-
*
182-
* {{{
183-
* import org.scalacheck._
184-
*
185-
* class ZeroSpecification(value: Int) extends Properties("Zero") {
186-
*
187-
* import org.scalacheck.Prop.{BooleanOperators, forAll}
188-
*
189-
* property("addition property") = forAll { n: Int => (n != 0) ==> (n + value == n) }
190-
*
191-
* property("additive inverse property") = forAll { n: Int => (n != 0) ==> (n + (-n) == value) }
192-
*
193-
* property("multiplication property") = forAll { n: Int => (n != 0) ==> (n * value == 0) }
194-
*
195-
* }
196-
* }}}
178+
* Look at the following specifications that define some properties for zero.
197179
*
198180
* You can use the check method of the `Properties` class to check all specified properties,
199181
* just like for simple `Prop` instances. In fact, `Properties` is a subtype of `Prop`,
200182
* so you can use it just as if it was a single property.
201183
*
202184
* That single property holds if and only if all of the contained properties hold.
185+
*
203186
*/
204-
def groupingProperties(res0: Int) = {
187+
def groupingProperties(res0: Int, res1: Int, res2: Int) = {
188+
import org.scalacheck.Properties
205189

206-
check(new ZeroSpecification(res0))
190+
class ZeroSpecification extends Properties("Zero") {
207191

208-
}
192+
import org.scalacheck.Prop.{BooleanOperators, forAll}
193+
194+
property("addition property") = forAll { n: Int => (n != 0) ==> (n + res0 == n) }
195+
196+
property("additive inverse property") = forAll { n: Int => (n != 0) ==> (n + (-n) == res1) }
197+
198+
property("multiplication property") = forAll { n: Int => (n != 0) ==> (n * res2 == 0) }
199+
200+
}
201+
202+
check(new ZeroSpecification)
203+
}
209204
}

src/test/scala/scalachecklib/PropertiesSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class PropertiesSpec extends Spec with Checkers {
5454
check(
5555
Test.testSuccess(
5656
PropertiesSection.groupingProperties _,
57-
0 :: HNil
57+
0 :: 0 :: 0 :: HNil
5858
)
5959
)
6060
}

0 commit comments

Comments
 (0)