Advertisement
pellekrogholt

Untitled

Sep 25th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. def make_huge_list(size: Int) = {
  2.  
  3. @scala.annotation.tailrec
  4. def inner_make_list(size: Int, acc: List[Char]) : List[Char] = {
  5. if (size == 0) acc
  6. else inner_make_list(size-1, 'X' :: acc)
  7. }
  8.  
  9. if (size <= 0) List()
  10. else inner_make_list(size, List())
  11. }
  12.  
  13. def huge_balanced: List[Char] = List.concat("(".toList, make_huge_list(999998), ")".toList);
  14. def huge_unbalanced: List[Char] = List.concat(make_huge_list(999999), ")".toList);
  15.  
  16. test("huge string balanced") {
  17. assert(balance(huge_balanced))
  18. }
  19.  
  20. test("huge string unbalanced") {
  21. assert(!balance(huge_unbalanced))
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement