Skip to content

Commit 79e5dda

Browse files
committed
prove basic schedule can not produce a negative temperature using scala check property (lawful) base testing for all valid timesteps in the timestep domain
1 parent b846388 commit 79e5dda

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

core/src/test/scala/aima/core/search/local/SimulatedAnnealingSearchSpec.scala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ package aima.core.search.local
22

33
import aima.core.search.local.SimulatedAnnealingSearch.{OverTimeStepLimit, Temperature, TemperatureResult}
44
import aima.core.search.local.time.TimeStep
5+
import org.scalacheck.{Arbitrary, Gen}
6+
import org.specs2.ScalaCheck
57
import org.specs2.mutable.Specification
68

79
import scala.util.{Success, Try}
810

911
/**
1012
* @author Shawn Garner
1113
*/
12-
class SimulatedAnnealingSearchSpec extends Specification {
14+
class SimulatedAnnealingSearchSpec extends Specification with ScalaCheck {
1315

1416
"BasicSchedule" >> {
1517
import aima.core.search.local.SimulatedAnnealingSearch.BasicSchedule.schedule
@@ -38,6 +40,20 @@ class SimulatedAnnealingSearchSpec extends Specification {
3840
"over limit check" in {
3941
increment(TimeStep.start, 99).map(schedule(_)) must beSuccessfulTry[TemperatureResult](OverTimeStepLimit)
4042
}
43+
44+
implicit val arbTimeStep: Arbitrary[TimeStep] = Arbitrary {
45+
for {
46+
numSteps <- Gen.choose[Int](0, 98)
47+
} yield increment(TimeStep.start, numSteps).get
48+
}
49+
50+
"must not create negative temperature" >> prop { ts: TimeStep =>
51+
schedule(ts) match {
52+
case Temperature(t) => t must be_>(0.00d)
53+
case other => ko(other.toString)
54+
}
55+
}
56+
4157
}
4258

4359
}

0 commit comments

Comments
 (0)