This commit is contained in:
JanUlrich 2022-05-30 14:36:41 +02:00
parent fdf3c03eb8
commit 43ad1c4964
2 changed files with 1 additions and 22 deletions

View File

@ -1,17 +1,7 @@
package hb.dhbw
class CartesianProduct[A](private val setOfSets: List[List[A]]){
def productWith(product: CartesianProduct[A]) = {
val ret = new CartesianProduct[A](setOfSets ++ product.setOfSets)
var base: Long = 1
ret.sizes = ret.setOfSets.map(_.size)
ret.sizes.foreach(size => {
base = base * size
})
ret.max = base
ret.i = i
ret
}
//def addPossibilities(Set[A]) //TODO
private var sizes: List[Int] = null
private var max: Long = 1

View File

@ -8,15 +8,4 @@ class CartesianProductTest extends FunSuite{
val result = List(1,2,3,4).map( _ => test.nextProduct())
assert(result.contains(Set(1,4)))
}
test("productWith"){
val test = new CartesianProduct[Int](Set(Set(1,2),Set(4,3)))
val test2 = new CartesianProduct[Int](Set(Set(5,6), Set(7,8)))
val test3 = test.productWith(test2)
val result = for( i <- 1 to 16) yield test3.nextProduct()
assert(result.contains(Set(2,3,6,8)))
assert(result.toSet.size == 16)
println(result)
}
}