Created
October 20, 2017 03:48
-
-
Save Ichoran/dc566ec09fbebee7b80e06758da43818 to your computer and use it in GitHub Desktop.
Example of what generated code looks like with collection-laws rewrite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Autogenerated test for collection List with element type String | |
package laws | |
class Test_Imm_List_Str(numb: Numbers, oper: Ops[String, Option[String]], inst: Instance[String, scala.collection.immutable.List[String]], lln: Int) | |
extends StrTest[scala.collection.immutable.List[String], Test_Imm_List_Str](numb, oper, inst, lln) { | |
import Test.ComparesTo | |
import Test.Logic | |
def renumber(numb: Numbers) = new Test_Imm_List_Str(numb, ops, instance, lawLine) | |
def reinstance(inst: Instance[String, scala.collection.immutable.List[String]]) = new Test_Imm_List_Str(num, ops, inst, lawLine) | |
def reoperate(oper: Ops[String, Option[String]]) = new Test_Imm_List_Str(num, oper, instance, lawLine) | |
def relaw(lln: Int) = new Test_Imm_List_Str(num, ops, instance, lln) | |
val lawNumbers = Set[Int](148, 150, 156, 174, 176, 178, 180, 182, 184, 186, 190, 192, 194, 196, 198, 221, 223, 234, 236, 238, 240, 242, 251, 253, 255, 262, 264, 266, 268, 270, 276, 282, 284, 286, 288, 290, 292, 294, 296, 298, 300, 302, 304, 318, 326, 328, 348, 352, 356, 358, 360, 362, 364, 368, 376, 381, 392, 396, 398, 402, 404, 406, 408, 410, 412, 416, 423, 425, 427, 429, 431, 433, 437, 439, 441, 443, 447, 449, 453, 455, 457, 461, 463, 467, 469, 473, 475, 482, 484, 486, 490, 492, 496, 498, 510, 519, 524, 529, 540, 550, 555, 559, 561, 563) | |
val obeys = lawNumbers.map(n => n -> Laws.byLineNumber(n)).toMap | |
def runLaw148: Boolean = { | |
x.map(f) theSameAs { val y = collection.mutable.ArrayBuffer.empty[A]; x.foreach(xi => y += f(xi)); y } | |
} | |
def runLaw150: Boolean = { | |
x.map(f) theSameAs { val y = collection.mutable.HashSet.empty[A]; x.foreach(y += _); y.map(f) } | |
} | |
def runLaw156: Boolean = { | |
{ | |
val flat = x.flatMap(xi => y.toList.take(intFrom(xi))) | |
val ref = collection.mutable.ArrayBuffer.empty[A] | |
x.foreach(xi => ref ++= y.toList.take(intFrom(xi))) | |
flat theSameAs ref | |
} | |
} | |
def runLaw174: Boolean = { | |
x.exists(p) == x.find(p).isDefined | |
} | |
def runLaw176: Boolean = { | |
x.forall(p) implies (x.isEmpty || x.exists(p)) | |
} | |
def runLaw178: Boolean = { | |
{ var y = false; x.foreach(xi => y |= p(xi)); y == x.exists(p) } | |
} | |
def runLaw180: Boolean = { | |
x.repr theSameAs x | |
} | |
def runLaw182: Boolean = { | |
x.toIterator theSameAs x | |
} | |
def runLaw184: Boolean = { | |
x.toStream theSameAs x | |
} | |
def runLaw186: Boolean = { | |
x.toTraversable theSameAs x | |
} | |
def runLaw190: Boolean = { | |
x.mkString == { val sb = new StringBuilder; x.foreach(sb ++= _.toString); sb.result } | |
} | |
def runLaw192: Boolean = { | |
x.mkString == { val sb = new StringBuilder; x.addString(sb); sb.result } | |
} | |
def runLaw194: Boolean = { | |
x.mkString == x.mkString("", "", "") | |
} | |
def runLaw196: Boolean = { | |
x.mkString("!") == x.mkString("", "!", "") | |
} | |
def runLaw198: Boolean = { | |
{ | |
(x.size == 0) || ( | |
x.mkString("!", "@", "#") == { | |
val sb = new StringBuilder | |
sb ++= "!" | |
x.foreach(sb ++= _.toString + "@") | |
sb.result.dropRight(1) + "#" | |
} | |
) | |
} | |
} | |
def runLaw221: Boolean = { | |
x.aggregate(zero)((b,a) => b, (b1,b2) => b1) == zero | |
} | |
def runLaw223: Boolean = { | |
x.aggregate(zero)((b,a) => b, (b1,b2) => b2) == zero | |
} | |
def runLaw234: Boolean = { | |
x.count(p) > 0 == x.exists(p) | |
} | |
def runLaw236: Boolean = { | |
(x.count(p) == x.size) == x.forall(p) | |
} | |
def runLaw238: Boolean = { | |
x.count(p) == { var k=0; x.foreach(xi => if (p(xi)) k += 1); k } | |
} | |
def runLaw240: Boolean = { | |
x.filter(p).size == x.count(p) | |
} | |
def runLaw242: Boolean = { | |
x.filter(p).forall(p) == true | |
} | |
def runLaw251: Boolean = { | |
x.foldLeft(a)(op) == x.foldRight(a)(op) | |
} | |
def runLaw253: Boolean = { | |
x.foldLeft(a)(op) == x./:(a)(op) | |
} | |
def runLaw255: Boolean = { | |
x.foldRight(a)(op) == x.:\(a)(op) | |
} | |
def runLaw262: Boolean = { | |
tryO{x.max} == tryO{ x.reduce(maxOf) } | |
} | |
def runLaw264: Boolean = { | |
tryO{x.maxBy(f)} == tryO{ val fx = x.map(f).max; x.find(xi => f(xi)==fx).get } | |
} | |
def runLaw266: Boolean = { | |
tryO{x.min} == tryO{ x.reduce(minOf) } | |
} | |
def runLaw268: Boolean = { | |
tryO{x.minBy(f)} == tryO{ val fx = x.map(f).min; x.find(xi => f(xi)==fx).get } | |
} | |
def runLaw270: Boolean = { | |
x.nonEmpty == x.exists(_ => true) | |
} | |
def runLaw276: Boolean = { | |
Set( | |
tryO{x.reduce(op)}, tryO{x.reduceLeft(op)}, tryO{x.reduceRight(op)}, | |
x.reduceOption(op), x.reduceLeftOption(op), x.reduceRightOption(op) | |
).size == 1 | |
} | |
def runLaw282: Boolean = { | |
x.size == x.count(_ => true) | |
} | |
def runLaw284: Boolean = { | |
x theSameAs x.to[List] | |
} | |
def runLaw286: Boolean = { | |
x.toArray theSameAs x | |
} | |
def runLaw288: Boolean = { | |
x.toBuffer theSameAs x | |
} | |
def runLaw290: Boolean = { | |
x.toIndexedSeq theSameAs x | |
} | |
def runLaw292: Boolean = { | |
x.toIterable theSameAs x | |
} | |
def runLaw294: Boolean = { | |
x.toList theSameAs x | |
} | |
def runLaw296: Boolean = { | |
x.map(xi => (xi,xi)).toMap theSameAs { val hm = new collection.mutable.HashMap[A,A]; x.foreach(xi => hm += xi -> xi); hm } | |
} | |
def runLaw298: Boolean = { | |
x.toSeq theSameAs x | |
} | |
def runLaw300: Boolean = { | |
x.toSet isPartOf x | |
} | |
def runLaw302: Boolean = { | |
x.toVector theSameAs x | |
} | |
def runLaw304: Boolean = { | |
val c = new collection.mutable.ArrayBuffer[A]; | |
x.withFilter(p).foreach(c += _); | |
c theSameAs x.filter(p) | |
} | |
def runLaw318: Boolean = { | |
x.++(y).size == x.size + y.size | |
} | |
def runLaw326: Boolean = { | |
(x.++(y)).take(x.size) theSameAs x | |
} | |
def runLaw328: Boolean = { | |
(x.++(y)).drop(x.size) theSameAs y | |
} | |
def runLaw348: Boolean = { | |
x.collect(pf) theSameAs x.filter(pf.isDefinedAt).map(pf) | |
} | |
def runLaw352: Boolean = { | |
x.contains(a) == x.exists(_ == a) | |
} | |
def runLaw356: Boolean = { | |
x.corresponds(x)(_ == _) | |
} | |
def runLaw358: Boolean = { | |
(x.size != y.size) implies !x.corresponds(y)(_ == _) | |
} | |
def runLaw360: Boolean = { | |
x.corresponds(y)((_,_) => false) implies !x.nonEmpty && !y.nonEmpty | |
} | |
def runLaw362: Boolean = { | |
x.drop(n).size == (0 max (x.size-(0 max n))) | |
} | |
def runLaw364: Boolean = { | |
x.drop(n) isPartOf x | |
} | |
def runLaw368: Boolean = { | |
val c = x.dropWhile(p); | |
c.take(1).toList match { | |
case Nil => true | |
case List(xi) => !p(xi) | |
case _ => false | |
} | |
} | |
def runLaw376: Boolean = { | |
val y = x.dropWhile(p) | |
y.nonEmpty implies y.exists(yi => !p(yi)) | |
} | |
def runLaw381: Boolean = { | |
x.dropWhile(p) isPartOf x | |
} | |
def runLaw392: Boolean = { | |
x.filterNot(p) theSameAs x.filter(xi => !p(xi)) | |
} | |
def runLaw396: Boolean = { | |
n <= 0 || x.grouped(n).map(_.size).sum == x.size | |
} | |
def runLaw398: Boolean = { | |
n <= 0 || m < 0 || { | |
var y = 0; x.grouped(n).drop(m).take(1).map(_.size).foreach(y = _); (y < n) implies !x.grouped(n).drop(m+1).nonEmpty | |
} | |
} | |
def runLaw402: Boolean = { | |
x.grouped((1 max n)).flatMap(xi => xi) theSameAs x | |
} | |
def runLaw404: Boolean = { | |
x.isEmpty == !x.nonEmpty | |
} | |
def runLaw406: Boolean = { | |
x.length == x.size | |
} | |
def runLaw408: Boolean = { | |
x.padTo(n, a).size == (n max x.size) | |
} | |
def runLaw410: Boolean = { | |
x.padTo(n, a).drop(x.size).forall(_ == a) | |
} | |
def runLaw412: Boolean = { | |
(n <= x.size) implies (x.padTo(n, a) theSameAs x) | |
} | |
def runLaw416: Boolean = { | |
val (t,f) = x.partition(p) | |
(t theSameAs x.filter(p)) && (f theSameAs x.filterNot(p)) | |
} | |
def runLaw423: Boolean = { | |
(n <= x.size) implies (x.patch(n, y, m).take(n) theSameAs x.take(n)) | |
} | |
def runLaw425: Boolean = { | |
(n <= x.size) implies (x.patch(n, y, m).drop(n).take(y.size) theSameAs y) | |
} | |
def runLaw427: Boolean = { | |
(n <= x.size) implies (x.patch(n, y, m).drop((0 max n)+y.size) theSameAs x.drop((0 max n)+(0 max m))) | |
} | |
def runLaw429: Boolean = { | |
(x sameElements y) == (x theSameAs y) | |
} | |
def runLaw431: Boolean = { | |
n < 0 || m >= x.size || { x.slice(n, m).size == (0 max ((0 max m)-n)) } | |
} | |
def runLaw433: Boolean = { | |
n < 0 || m >= x.size || { x.slice(n, m) theSameAs x.drop(n).take((0 max m)-n) } | |
} | |
def runLaw437: Boolean = { | |
x.span(p)._1.forall(p) | |
} | |
def runLaw439: Boolean = { | |
(x.span(p)._2.size) > 0 implies !x.span(p)._2.take(1).exists(p) | |
} | |
def runLaw441: Boolean = { | |
(x.span(p)._2.size) > 0 implies !x.span(p)._2.forall(p) | |
} | |
def runLaw443: Boolean = { | |
val (x1, x2) = x.span(p); val n = x.span(p)._1.size; (x1 theSameAs x.take(n)) && (x2 theSameAs x.drop(n)) | |
} | |
def runLaw447: Boolean = { | |
x.take(n).size == ((0 max n) min x.size) | |
} | |
def runLaw449: Boolean = { | |
x.take(n) isPartOf x | |
} | |
def runLaw453: Boolean = { | |
x.takeWhile(p).forall(p) | |
} | |
def runLaw455: Boolean = { | |
x.takeWhile(p) isPartOf x | |
} | |
def runLaw457: Boolean = { | |
x.takeWhile(p).size + x.dropWhile(p).size == x.size | |
} | |
def runLaw461: Boolean = { | |
x.zip(y).map(_._1) theSameAs x.take(x.size min y.size) | |
} | |
def runLaw463: Boolean = { | |
x.zip(y).map(_._2) theSameAs y.take(x.size min y.size) | |
} | |
def runLaw467: Boolean = { | |
x.zipAll(y, a, b).map(_._1) theSameAs x.padTo(x.size max y.size, a) | |
} | |
def runLaw469: Boolean = { | |
x.zipAll(y, a, b).map(_._2) theSameAs y.padTo(x.size max y.size, b) | |
} | |
def runLaw473: Boolean = { | |
x.zipWithIndex.map(_._1) theSameAs x | |
} | |
def runLaw475: Boolean = { | |
x.zipWithIndex.map(_._2) theSameAs (0 until x.size) | |
} | |
def runLaw482: Boolean = { | |
x.++:(y) theSameAs y.++(x) | |
} | |
def runLaw484: Boolean = { | |
x.::(a).size == x.size+1 | |
} | |
def runLaw486: Boolean = { | |
x.::(a).head == a | |
} | |
def runLaw490: Boolean = { | |
x.+:(a).size == x.size+1 | |
} | |
def runLaw492: Boolean = { | |
x.+:(a).head == a | |
} | |
def runLaw496: Boolean = { | |
x.:+(a).size == x.size+1 | |
} | |
def runLaw498: Boolean = { | |
x.:+(a).last == a | |
} | |
def runLaw510: Boolean = { | |
x.:::(y) theSameAs y.++(x) | |
} | |
def runLaw519: Boolean = { | |
x.size > 8 || { | |
val n = x.combinations(r).size; | |
((r > x.size) implies (n == 0)) && x.combinations(r).toSet.size == n | |
} | |
} | |
def runLaw524: Boolean = { | |
x.size > 8 || r == 0 || r > x.size || { | |
val s = x.toVector | |
x.combinations(r).forall(_ isPartOf s) | |
} | |
} | |
def runLaw529: Boolean = { | |
x.containsSlice(y) implies ( | |
y.size == 0 || | |
( Iterator.from(0). | |
map(x.drop). | |
takeWhile(_.nonEmpty). | |
exists(_.take(y.size) theSameAs y) | |
) | |
) | |
} | |
def runLaw540: Boolean = { | |
val List(xg,yg,xdyg) = | |
List(x,y,x.diff(y)).map(_.groupBy(identity).mapValues(_.size).toMap) | |
xg.forall{ case (k, n) => | |
val m = n - yg.getOrElse(k,0) | |
(m > 0) implies (xdyg.getOrElse(k,0) == m) | |
} | |
} | |
def runLaw550: Boolean = { | |
val s = x.toSet | |
x.distinct.size == s.size && x.forall(s) | |
} | |
def runLaw555: Boolean = { | |
x.dropRight(nn) theSameAs x.take(x.size - math.max(0, nn)) | |
} | |
def runLaw559: Boolean = { | |
x.endsWith(y) == (x.drop(math.max(0, x.size-y.size)) theSameAs y) | |
} | |
def runLaw561: Boolean = { | |
x.groupBy(g).keySet theSameAs x.map(g).toSet | |
} | |
def runLaw563: Boolean = { | |
x.groupBy(g).toMap.forall{ case (k,vs) => x.filter(xi => g(xi)==k) theSameAs vs } | |
} | |
val lawTable: Map[Int, () => Boolean] = Map( | |
148 -> (runLaw148 _), | |
150 -> (runLaw150 _), | |
156 -> (runLaw156 _), | |
174 -> (runLaw174 _), | |
176 -> (runLaw176 _), | |
178 -> (runLaw178 _), | |
180 -> (runLaw180 _), | |
182 -> (runLaw182 _), | |
184 -> (runLaw184 _), | |
186 -> (runLaw186 _), | |
190 -> (runLaw190 _), | |
192 -> (runLaw192 _), | |
194 -> (runLaw194 _), | |
196 -> (runLaw196 _), | |
198 -> (runLaw198 _), | |
221 -> (runLaw221 _), | |
223 -> (runLaw223 _), | |
234 -> (runLaw234 _), | |
236 -> (runLaw236 _), | |
238 -> (runLaw238 _), | |
240 -> (runLaw240 _), | |
242 -> (runLaw242 _), | |
251 -> (runLaw251 _), | |
253 -> (runLaw253 _), | |
255 -> (runLaw255 _), | |
262 -> (runLaw262 _), | |
264 -> (runLaw264 _), | |
266 -> (runLaw266 _), | |
268 -> (runLaw268 _), | |
270 -> (runLaw270 _), | |
276 -> (runLaw276 _), | |
282 -> (runLaw282 _), | |
284 -> (runLaw284 _), | |
286 -> (runLaw286 _), | |
288 -> (runLaw288 _), | |
290 -> (runLaw290 _), | |
292 -> (runLaw292 _), | |
294 -> (runLaw294 _), | |
296 -> (runLaw296 _), | |
298 -> (runLaw298 _), | |
300 -> (runLaw300 _), | |
302 -> (runLaw302 _), | |
304 -> (runLaw304 _), | |
318 -> (runLaw318 _), | |
326 -> (runLaw326 _), | |
328 -> (runLaw328 _), | |
348 -> (runLaw348 _), | |
352 -> (runLaw352 _), | |
356 -> (runLaw356 _), | |
358 -> (runLaw358 _), | |
360 -> (runLaw360 _), | |
362 -> (runLaw362 _), | |
364 -> (runLaw364 _), | |
368 -> (runLaw368 _), | |
376 -> (runLaw376 _), | |
381 -> (runLaw381 _), | |
392 -> (runLaw392 _), | |
396 -> (runLaw396 _), | |
398 -> (runLaw398 _), | |
402 -> (runLaw402 _), | |
404 -> (runLaw404 _), | |
406 -> (runLaw406 _), | |
408 -> (runLaw408 _), | |
410 -> (runLaw410 _), | |
412 -> (runLaw412 _), | |
416 -> (runLaw416 _), | |
423 -> (runLaw423 _), | |
425 -> (runLaw425 _), | |
427 -> (runLaw427 _), | |
429 -> (runLaw429 _), | |
431 -> (runLaw431 _), | |
433 -> (runLaw433 _), | |
437 -> (runLaw437 _), | |
439 -> (runLaw439 _), | |
441 -> (runLaw441 _), | |
443 -> (runLaw443 _), | |
447 -> (runLaw447 _), | |
449 -> (runLaw449 _), | |
453 -> (runLaw453 _), | |
455 -> (runLaw455 _), | |
457 -> (runLaw457 _), | |
461 -> (runLaw461 _), | |
463 -> (runLaw463 _), | |
467 -> (runLaw467 _), | |
469 -> (runLaw469 _), | |
473 -> (runLaw473 _), | |
475 -> (runLaw475 _), | |
482 -> (runLaw482 _), | |
484 -> (runLaw484 _), | |
486 -> (runLaw486 _), | |
490 -> (runLaw490 _), | |
492 -> (runLaw492 _), | |
496 -> (runLaw496 _), | |
498 -> (runLaw498 _), | |
510 -> (runLaw510 _), | |
519 -> (runLaw519 _), | |
524 -> (runLaw524 _), | |
529 -> (runLaw529 _), | |
540 -> (runLaw540 _), | |
550 -> (runLaw550 _), | |
555 -> (runLaw555 _), | |
559 -> (runLaw559 _), | |
561 -> (runLaw561 _), | |
563 -> (runLaw563 _) | |
) | |
def runLaw(n: Int): Option[Boolean] = lawTable.get(n).map(_()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment