exps/bit-test.scala
changeset 322 22e34f93cd5d
parent 318 43e070803c1c
child 323 09ce1cdb70ab
equal deleted inserted replaced
321:72f54acfb976 322:22e34f93cd5d
   417   val result = code
   417   val result = code
   418   val end = System.nanoTime()
   418   val end = System.nanoTime()
   419   (result, (end - start))
   419   (result, (end - start))
   420 }
   420 }
   421 
   421 
   422 //size: of a Aregx for testing purposes 
   422 //size: of a Rrexp and ARexp for testing purposes 
   423 def size(r: Rexp) : Int = r match {
   423 def size(r: Rexp) : Int = r match {
   424   case ZERO => 1
   424   case ZERO => 1
   425   case ONE => 1
   425   case ONE => 1
   426   case PRED(_,_) => 1
   426   case PRED(_,_) => 1
   427   case SEQ(r1, r2) => 1 + size(r1) + size(r2)
   427   case SEQ(r1, r2) => 1 + size(r1) + size(r2)
   688 
   688 
   689 println("Partial searching: ")
   689 println("Partial searching: ")
   690 enum(2, "abc").map(tests_ders_bsimp(strs(1, "abc"))).
   690 enum(2, "abc").map(tests_ders_bsimp(strs(1, "abc"))).
   691   flatten.toSet.flatten.minBy(a => asize(a._1))
   691   flatten.toSet.flatten.minBy(a => asize(a._1))
   692 
   692 
       
   693 // tests about good
       
   694 def good (a: ARexp) : Boolean = a match {
       
   695   case AZERO => false
       
   696   case AONE(_) => true
       
   697   case APRED(_, _, _) => true
       
   698   case AALTS(_, Nil) => false
       
   699   case AALTS(_, rs) => rs.forall(good(_))
       
   700   case ASEQ(_, r1, r2) => good(r1) & good(r2)
       
   701   case ASTAR(_, _) => true
       
   702 }
       
   703 
       
   704 def tests_good(r: Rexp) = {
       
   705   val a = bsimp(internalise(r))
       
   706   if  (! good(a) & a != AZERO) {
       
   707         println(s"Counter-example on ${astring(a)}")
       
   708         Some(a)  
       
   709   } else None 
       
   710 }
       
   711 
       
   712 enum(2, "abc").map(tests_good).toSet
       
   713 
       
   714 val g1 = AALTS(Nil, Nil)
       
   715 good(g1)
       
   716 good(bsimp(g1))
   693 
   717 
   694 
   718 
   695 //tests retrieve and lexing
   719 //tests retrieve and lexing
   696 
   720 
   697 def tests_retrieve_lex(ss: Set[String])(r: Rexp) = {
   721 def tests_retrieve_lex(ss: Set[String])(r: Rexp) = {