Write a program that, given a number, prints it.
But for multiples of three print
Fizz
instead of the number and for the multiples of five printBuzz
.
def mult3(i: Int) = !(i % 3 > 0)def mult5(i: Int) = !(i % 5 > 0)def fizzBuzz(i: Int) = if mult3(i) then "Fizz" else if mult5(i) then "Buzz" else i.toString
Write a program that, given a number, prints it.
But for multiples of three print
Fizz
instead of the number and for the multiples of five printBuzz
.
def mult3(i: Int) = !(i % 3 > 0)def mult5(i: Int) = !(i % 5 > 0)def fizzBuzz(i: Int) = if mult3(i) then "Fizz" else if mult5(i) then "Buzz" else i.toString
Write a program that, given a number, prints it.
But for multiples of three print
Fizz
instead of the number and for the multiples of five printBuzz
.
def mult3(i: Int) = !(i % 3 > 0)def mult5(i: Int) = !(i % 5 > 0)def fizzBuzz(i: Int) = if mult3(i) then "Fizz" else if mult5(i) then "Buzz" else i.toString
Write a program that, given a number, prints it.
But for multiples of three print
Fizz
instead of the number and for the multiples of five printBuzz
.
def mult3(i: Int) = !(i % 3 > 0)def mult5(i: Int) = !(i % 5 > 0)def fizzBuzz(i: Int) = if mult3(i) then "Fizz" else if mult5(i) then "Buzz" else i.toString
Write a program that, given a number, prints it.
But for multiples of three print
Fizz
instead of the number and for the multiples of five printBuzz
.
def mult3(i: Int) = !(i % 3 > 0)def mult5(i: Int) = !(i % 5 > 0)def fizzBuzz(i: Int) = if mult3(i) then "Fizz" else if mult5(i) then "Buzz" else i.toString
Write a program that, given a number, prints it.
But for multiples of three print
Fizz
instead of the number and for the multiples of five printBuzz
.
def mult3(i: Int) = !(i % 3 > 0)def mult5(i: Int) = !(i % 5 > 0)def fizzBuzz(i: Int) = if mult3(i) then "Fizz" else if mult5(i) then "Buzz" else i.toString
Write a program that, given a number, prints it.
But for multiples of three print
Fizz
instead of the number and for the multiples of five printBuzz
.
def mult3(i: Int) = !(i % 3 > 0)def mult5(i: Int) = !(i % 5 > 0)def fizzBuzz(i: Int) = if mult3(i) then "Fizz" else if mult5(i) then "Buzz" else i.toString
class ListTests extends AnyFunSuite: test("List(3, 2, 1) should sort to List(1, 2, 3)") { assert(List(3, 2, 1).sorted == List(1, 2, 3)) }
class ListTests extends AnyFunSuite: test("List(3, 2, 1) should sort to List(1, 2, 3)") { assert(List(3, 2, 1).sorted == List(1, 2, 3)) }
class ListTests extends AnyFunSuite: test("List(3, 2, 1) should sort to List(1, 2, 3)") { assert(List(3, 2, 1).sorted == List(1, 2, 3)) }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") }
new FizzBuzzSuite().execute()
new FizzBuzzSuite().execute()// rs$line$3$FizzBuzzSuite:// - n multiple of 3 outputs Fizz// - n multiple of 5 outputs Buzz// - n multiple of neither 3 or 5 outputs n
fizzBuzz(15)
fizzBuzz(15)// val res1: String = Fizz
fizzBuzz(15)// val res1: String = Fizz
n % 3 | n % 5 | Output | |
---|---|---|---|
T | T | FizzBuzz | |
T | F | Fizz | |
F | T | Buzz | |
F | F | n |
n % 3 | n % 5 | Output | |
---|---|---|---|
T | T | FizzBuzz | |
T | F | Fizz | |
F | T | Buzz | |
F | F | n |
n % 3 | n % 5 | Output | |
---|---|---|---|
T | T | FizzBuzz | |
T | F | Fizz | |
F | T | Buzz | |
F | F | n |
n % 3 | n % 5 | Output | |
---|---|---|---|
T | T | FizzBuzz | |
T | F | Fizz | |
F | T | Buzz | |
F | F | n |
n % 3 | n % 5 | Output | |
---|---|---|---|
T | T | FizzBuzz | |
T | F | Fizz | |
F | T | Buzz | |
F | F | n |
n % 3 | n % 5 | Output | |
---|---|---|---|
T | T | FizzBuzz | |
T | F | Fizz | |
F | T | Buzz | |
F | F | n |
n % 3 | n % 5 | Output | |
---|---|---|---|
T | T | FizzBuzz | |
T | F | Fizz | |
F | T | Buzz | |
F | F | n |
def mult3(i: Int) = !(i % 3 > 0)def mult5(i: Int) = !(i % 5 > 0)def fizzBuzz(i: Int) = if mult3(i) then "Fizz" else if mult5(i) then "Buzz" else i.toString
def mult3(i: Int) = !(i % 3 > 0)def mult5(i: Int) = !(i % 5 > 0)def fizzBuzz(i: Int) = if mult3(i) then if mult5(i) then "FizzBuzz" else "Fizz" else if mult5(i) then "Buzz" else i.toString
def mult3(i: Int) = !(i % 3 > 0)def mult5(i: Int) = !(i % 5 > 0)def fizzBuzz(i: Int) = if mult3(i) then if mult5(i) then "FizzBuzz" else "Fizz" else if mult5(i) then "Buzz" else i.toString
def mult3(i: Int) = !(i % 3 > 0)def mult5(i: Int) = !(i % 5 > 0)def fizzBuzz(i: Int) = if mult3(i) then if mult5(i) then "FizzBuzz" else "Fizz" else if mult5(i) then "Buzz" else i.toString
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
new FizzBuzzSuite().execute()
new FizzBuzzSuite().execute()// rs$line$7$FizzBuzzSuite:// - n multiple of 3 outputs Fizz// - n multiple of 5 outputs Buzz// - n multiple of neither 3 or 5 outputs n// - n multiple of 3 and 5 outputs FizzBuzz
fizzBuzz(-3)
fizzBuzz(-3)// val res3: String = FizzBuzz
fizzBuzz(-3)// val res3: String = FizzBuzz
Example-based testing is:
Example-based testing is:
Example-based testing is:
very good at the oracle problem.
very bad at the test case generation problem.
Example-based testing is:
very good at the oracle problem.
very bad at the test case generation problem.
a little bit discouraging...
forAll { (is: List[Int]) => is.sorted.diff(is).isEmpty}
forAll { (is: List[Int]) => is.sorted.diff(is).isEmpty}
forAll { (is: List[Int]) => is.sorted.diff(is).isEmpty}
val propFizzBuzz = forAll { (i: Int) => if mult3(i) then if mult5(i) then fizzBuzz(i) == "FizzBuzz" else fizzBuzz(i) == "Fizz" else if mult5(i) then fizzBuzz(i) == "Buzz" else fizzBuzz(i) == i.toString}
val propFizzBuzz = forAll { (i: Int) => if mult3(i) then if mult5(i) then fizzBuzz(i) == "FizzBuzz" else fizzBuzz(i) == "Fizz" else if mult5(i) then fizzBuzz(i) == "Buzz" else fizzBuzz(i) == i.toString}
val propFizzBuzz = forAll { (i: Int) => if mult3(i) then if mult5(i) then fizzBuzz(i) == "FizzBuzz" else fizzBuzz(i) == "Fizz" else if mult5(i) then fizzBuzz(i) == "Buzz" else fizzBuzz(i) == i.toString}
val propFizzBuzz = forAll { (i: Int) => if mult3(i) then if mult5(i) then fizzBuzz(i) == "FizzBuzz" else fizzBuzz(i) == "Fizz" else if mult5(i) then fizzBuzz(i) == "Buzz" else fizzBuzz(i) == i.toString}
val propFizzBuzz = forAll { (i: Int) => if mult3(i) then if mult5(i) then fizzBuzz(i) == "FizzBuzz" else fizzBuzz(i) == "Fizz" else if mult5(i) then fizzBuzz(i) == "Buzz" else fizzBuzz(i) == i.toString}
propFizzBuzz.check()
propFizzBuzz.check()// + OK, passed 100 tests.
val propFizzBuzz = forAll { (i: Int) => if mult3(i) then if mult5(i) then fizzBuzz(i) == "FizzBuzz" else fizzBuzz(i) == "Fizz" else if mult5(i) then fizzBuzz(i) == "Buzz" else fizzBuzz(i) == i.toString}
forAll { (is: List[Int]) => fastSort(is) == is.sorted}
forAll { (is: List[Int]) => fastSort(is) == is.sorted}
forAll { (is: List[Int]) => fastSort(is) == is.sorted}
forAll { (is: List[Int]) => fastSort(is) == is.sorted}
forAll { (i: Int) => math.abs(i) >= 0}
forAll { (i: Int) => math.abs(i) >= 0}
forAll { (i: Int) => math.abs(i) >= 0}
val propValidFizzBuzz = forAll { (i: Int) => fizzBuzz(i) in Set(i.toString, "Fizz", "Buzz", "FizzBuzz")}
val propValidFizzBuzz = forAll { (i: Int) => fizzBuzz(i) in Set(i.toString, "Fizz", "Buzz", "FizzBuzz")}
val propValidFizzBuzz = forAll { (i: Int) => fizzBuzz(i) in Set(i.toString, "Fizz", "Buzz", "FizzBuzz")}
propValidFizzBuzz.check()
propValidFizzBuzz.check()// + OK, passed 100 tests.
forAll { (i: Int) => i.toString.toInt == i}
forAll { (i: Int) => i.toString.toInt == i}
forAll { (i: Int) => i.toString.toInt == i}
forAll { (i: Int) => i.toString.toInt == i}
Track( artist = "Iron Maiden", year = 1982, album = "The Number of the Beast", name = "Children of the Damned")
Track( artist = "Iron Maiden", year = 1982, album = "The Number of the Beast", name = "Children of the Damned")
{ "artist" : "Iron Maiden", "year" : 1982, "album" : "The Number of the Beast", "name" : "Children of the Damned"}
Track( artist = "Iron Maiden", year = 1970, album = "The Number of the Beast", name = "Children of the Damned")
Track( artist = "Iron Maiden", year = 1970, album = "The Number of the Beast", name = "Children of the Damned")
val propInvolutiveFizzBuzz = forAll { (i: Int) => !(mult3(i) || mult5(i)) ==> (fizzBuzz(i).toInt == i)}
val propInvolutiveFizzBuzz = forAll { (i: Int) => !(mult3(i) || mult5(i)) ==> (fizzBuzz(i).toInt == i)}
val propInvolutiveFizzBuzz = forAll { (i: Int) => !(mult3(i) || mult5(i)) ==> (fizzBuzz(i).toInt == i)}
val propInvolutiveFizzBuzz = forAll { (i: Int) => !(mult3(i) || mult5(i)) ==> (fizzBuzz(i).toInt == i)}
val propInvolutiveFizzBuzz = forAll { (i: Int) => !(mult3(i) || mult5(i)) ==> (fizzBuzz(i).toInt == i)}
val propInvolutiveFizzBuzz = forAll { (i: Int) => !(mult3(i) || mult5(i)) ==> (fizzBuzz(i).toInt == i)}
propInvolutiveFizzBuzz.check()
propInvolutiveFizzBuzz.check()// + OK, passed 100 tests.
forAll { (is: List[Int]) => is.sorted == is.sorted.sorted}
forAll { (is: List[Int]) => is.sorted == is.sorted.sorted}
forAll { (is: List[Int]) => is.sorted == is.sorted.sorted}
forAll { (is: List[Int]) => is.sorted == is.sorted.sorted}
artist |
year |
album |
name |
---|---|---|---|
Iron Maiden | 1982 | The Number of the Beast | Children of the Damned |
Iron Maiden | 1982 | The Number of the Beast | Invaders |
Iron Maiden | 1982 | The Number of the Beast | Gangland |
db.delete( artist = "Iron Maiden", name = "Gangland")
artist |
year |
album |
name |
---|---|---|---|
Iron Maiden | 1982 | The Number of the Beast | Children of the Damned |
Iron Maiden | 1982 | The Number of the Beast | Invaders |
db.delete( artist = "Iron Maiden", name = "Gangland")
artist |
year |
album |
name |
---|---|---|---|
Iron Maiden | 1982 | The Number of the Beast | Children of the Damned |
db.delete( artist = "Iron Maiden", name = "Gangland")
artist |
year |
album |
name |
---|---|---|---|
Iron Maiden | 1982 | The Number of the Beast | Children of the Damned |
db.delete( artist = "Iron Maiden", name = "Gangland")
forAll { (is: List[Int]) => is.sorted.diff(is).isEmpty}
forAll { (is: List[Int]) => is.sorted.diff(is).isEmpty}
forAll { (is: List[Int]) => is.sorted.diff(is).isEmpty}
artist |
year |
album |
name |
---|---|---|---|
Iron Maiden | 1982 | The Number of the Beast | Children of the Damned |
Iron Maiden | 1982 | The Number of the Beast | Invaders |
artist |
year |
album |
name |
---|---|---|---|
İ̵̺͝ṛ̸̣͕̐͜o̴̢̎̿̓̌n̸̥͙̬̣̾́͛̾̌͘ͅ ̶̻͂M̷̗̣̠̠̎̀ȧ̸̛͔͇̐͘į̵̗̞̩̯̫̇̔̾̋̕͝d̵̟͓͆̅̇̋̐̚ͅe̷̯̪̙̼̩̩͐n̴̛̗̟͈͇̖̎̈̕ | 1̶͍͓̣̔̍́̒̒̅͘͜9̷̬̖̹̗̻͍̋͗̈́͠8̶͓̫̹̹̍2̸̨̲̝̏͌ | T̸̜̟͕̩̘̃̇͂͠h̶̦̓͋̇͝e̴̢̝̱̦͎͗͂̅̓͜ͅ ̶̝̬͠͝Ǹ̵̛̘̺̯̃̈́̍ù̷̱̖m̷̗͙̱̥͇̹͑̎̂͊̈́́̌b̸̢̦̪̽̅̂̑e̴̤̫̝̎̈́̇r̵͇̥̃̃̈͋̎̋͗͜ ̴͇̖̼͙̥̲̹̄̀ò̷͉̠̒f̶̲͇̳͛̔̃̽ ̸͍̉̚͝t̶̼̗̬̞̣̂͗͠͠͝h̴̰͒̾̑͐́͝ě̷̠̤͎̳͍̿͆́̕͝ ̸̭̬̊̐̾̍B̷̨̑é̴̡̟͔͖̏̃̔̓͝͠ą̷͉̫͇̫̈́̍̄́̃s̵͍̀̅͂͂͑̌ẗ̷̡̪̙͉͔́͑͗̇̋̑ | C̵͚̣̬̠̞̝̰̐̍̃h̷̥͛͂͋̚̚ï̴̤l̴͉̳̘̝͖̤͋͝d̴̢̲̫̯͙̺̮́̈́̕r̸̢̗̥͇̻͓͗̋̆́ȇ̸̲̉̆n̵̞̙͎̠̲͕̭̅̃̉̂ ̵͔̦͙̯̎͂̑̚͝õ̷̳̱͈̻̤̠̫̽̓̑̊͒f̸̦͋ͅ ̴̹̖̌ṫ̷̻̼͖͗̉̀̑h̴̹͎̰̬̟͊̍ͅe̸̤̱͛́͑ ̸̞̾͊͠D̵̢̜̬̳̍̑͛̄͆̀̅a̴͙̼̤̤͓͇̟̒̈́͋m̷̡̞̬̞̬͆̔̿n̴̨̢̖͉͓̥̂̄͘ë̴̬͚͎̭̭ͅd̸̢͕̼̗̠̂ |
Ì̷̧̺͓͕̘͓̯̗̬͈̤̗̝̰͜ȓ̵̨̜̟̱̘̟̬̙̯̱͍̩̭̈̆̅̍̌̿́̈́́̚͜͝ͅo̴̡͗͗͛̑̿̾͒͂̎̆n̶͖̳͖͉̗͕̱͔̱̖̫̽̎͜ͅ ̸̢̨̛͇͚͔̘̦̘̱̮̖̿͑̒̉̽̎́̑̚̚̕M̷̜͖̊͗̅̆̏̈́͛̍̂̉́̃̚̕͝ả̷̡̛̫͔̳̞̻͔͉̜̍̅̈́̆͛͒̋̑͠i̵̢̡͎̯̙͇͍̇͊̃̓̚͜ͅd̸̟̤̼̲̈́̎̑͜ͅȩ̸͓̝̘̙͉̼̺̖̳͓̩̽̕ͅn̴͈̈̃̿͝ | 1̴̛͈̣̲̹͗̾͂͆̒̓͛̋͝9̵̨̢̨̻̲̬͕̲͔͖̘̀̿͝ͅ8̷̩̹̣̦̙͖͚̞̮́̉̑̓̉͑̈̾́͊̀̽͛͘̚2̵̡̘̠̼͙̅̇͛̽͒̀̄̾́̋̎͐͛͝ | T̷̢̟̙̥̬̰͎͚͈͕̬͆̋͊͛̂̓̈́͊̌̀͆̅̐͘͝ȟ̴̛̹̝͕͒͗è̵̛̩͇͎̤̪͍͎̳̺͔̖̝͖͊̏̀̽͝ ̵͕͇͌͌́͛̑̏͊̈̔̿̚̕͠͝N̴̤̥̖̠͍̻̤̣͈̩̞̾̍̉͐͋̇̈̈́̓̈́̚ͅu̵̲̹̙̦̞̎̏͗͋̌͐̈́͘͜͝͝m̶̡̙̖̳̖͇̻̰̼̝̖̎̈̈̄́̀̽̈́͘͜͝b̸̡̙͚̙̮̀̀̅́̔́̿̑͆̂͒̕è̷̫͕̗̰̌̈́̏͗͆͂r̶̡̢̨̛̛̙̖̲͔̥̲͕̈́̀͆̀̅̀̔̃̿̉̽͝͝ ̵̨͍͎͈̹̺̟̠̪̼̟̟͔̜̆̈́̈́o̶̡̧̯̠̜̤͊̒̀͆̒̀̋̅̽̕͜͝ͅf̸͓̥̻͚̘̹͈͉̱̆̅̊̿͑͛́͆̽̋͘͜͜ ̶̣̭͙̯͇̦͂̋͆͆̕ţ̴̡̨̭̭̺̣̲̤͎̩̮̮̥̿́̔́̂͂h̵͉̤͛͊͛͐͒͒ė̶̜̰͓̤̼̖̜̣͎̫̑̍̌́̂̈̌͆̍ ̴̘̞̖̳͕̳͑̀̆̑͜B̷̨͈̹̣̘̰͕͉̰̹͗̔ȩ̷̡̠̙̖̱̜̲̤͚̼͓̠͛̾̓͆̅̒͂̅̀̿͘͘ạ̶̢̨̮̩͇͚͓̀̄̐̈́̇̇͊̄̾̕͝͝s̵̡̛͚̭̞͌̋̐̑͑̓̒̋͊͊͌̈̎̚ṱ̴̫̤̩͂͒̅̋̓̓̿̅̈́̎ | I̴̢̦̠͈̊̆͌͝͝ͅn̶̛͈̺̜͇̲̭͓͉̎̽̓̊̈̈́̾̔́̽̇͘v̷͈̘̞̬̼̲̍͊͊̋̓̕ą̷̰͙͙̖̖̤̬͙̃d̷̠̀́̓͆̽̽̽̓͘ȩ̵̤̱͓̫̻̫̯̪̎͌̇̆̄̓ͅr̴̗̹̪̬̘̪̝̰͆̒͆̋̃̃̏̈͑̅͝ş̴͎̭̻͔̘͈͉̟̻͈̯̩͓̔̐ |
artist |
year |
album |
name |
---|---|---|---|
Iron Maiden | 1982 | The Number of the Beast | Children of the Damned |
Iron Maiden | 1982 | The Number of the Beast | Invaders |
forAll { (cmds: List[Command]) => cmds.forall { cmd => db.execute(cmd) notCorrupt(db) }}
artist |
year |
album |
name |
---|---|---|---|
Iron Maiden | 1982 | The Number of the Beast | Children of the Damned |
Iron Maiden | 1982 | The Number of the Beast | Invaders |
forAll { (cmds: List[Command]) => cmds.forall { cmd => db.execute(cmd) notCorrupt(db) }}
artist |
year |
album |
name |
---|---|---|---|
Iron Maiden | 1982 | The Number of the Beast | Children of the Damned |
Iron Maiden | 1982 | The Number of the Beast | Invaders |
forAll { (cmds: List[Command]) => cmds.forall { cmd => db.execute(cmd) notCorrupt(db) }}
artist |
year |
album |
name |
---|---|---|---|
İ̵̺͝ṛ̸̣͕̐͜o̴̢̎̿̓̌n̸̥͙̬̣̾́͛̾̌͘ͅ ̶̻͂M̷̗̣̠̠̎̀ȧ̸̛͔͇̐͘į̵̗̞̩̯̫̇̔̾̋̕͝d̵̟͓͆̅̇̋̐̚ͅe̷̯̪̙̼̩̩͐n̴̛̗̟͈͇̖̎̈̕ | 1̶͍͓̣̔̍́̒̒̅͘͜9̷̬̖̹̗̻͍̋͗̈́͠8̶͓̫̹̹̍2̸̨̲̝̏͌ | T̸̜̟͕̩̘̃̇͂͠h̶̦̓͋̇͝e̴̢̝̱̦͎͗͂̅̓͜ͅ ̶̝̬͠͝Ǹ̵̛̘̺̯̃̈́̍ù̷̱̖m̷̗͙̱̥͇̹͑̎̂͊̈́́̌b̸̢̦̪̽̅̂̑e̴̤̫̝̎̈́̇r̵͇̥̃̃̈͋̎̋͗͜ ̴͇̖̼͙̥̲̹̄̀ò̷͉̠̒f̶̲͇̳͛̔̃̽ ̸͍̉̚͝t̶̼̗̬̞̣̂͗͠͠͝h̴̰͒̾̑͐́͝ě̷̠̤͎̳͍̿͆́̕͝ ̸̭̬̊̐̾̍B̷̨̑é̴̡̟͔͖̏̃̔̓͝͠ą̷͉̫͇̫̈́̍̄́̃s̵͍̀̅͂͂͑̌ẗ̷̡̪̙͉͔́͑͗̇̋̑ | C̵͚̣̬̠̞̝̰̐̍̃h̷̥͛͂͋̚̚ï̴̤l̴͉̳̘̝͖̤͋͝d̴̢̲̫̯͙̺̮́̈́̕r̸̢̗̥͇̻͓͗̋̆́ȇ̸̲̉̆n̵̞̙͎̠̲͕̭̅̃̉̂ ̵͔̦͙̯̎͂̑̚͝õ̷̳̱͈̻̤̠̫̽̓̑̊͒f̸̦͋ͅ ̴̹̖̌ṫ̷̻̼͖͗̉̀̑h̴̹͎̰̬̟͊̍ͅe̸̤̱͛́͑ ̸̞̾͊͠D̵̢̜̬̳̍̑͛̄͆̀̅a̴͙̼̤̤͓͇̟̒̈́͋m̷̡̞̬̞̬͆̔̿n̴̨̢̖͉͓̥̂̄͘ë̴̬͚͎̭̭ͅd̸̢͕̼̗̠̂ |
Ì̷̧̺͓͕̘͓̯̗̬͈̤̗̝̰͜ȓ̵̨̜̟̱̘̟̬̙̯̱͍̩̭̈̆̅̍̌̿́̈́́̚͜͝ͅo̴̡͗͗͛̑̿̾͒͂̎̆n̶͖̳͖͉̗͕̱͔̱̖̫̽̎͜ͅ ̸̢̨̛͇͚͔̘̦̘̱̮̖̿͑̒̉̽̎́̑̚̚̕M̷̜͖̊͗̅̆̏̈́͛̍̂̉́̃̚̕͝ả̷̡̛̫͔̳̞̻͔͉̜̍̅̈́̆͛͒̋̑͠i̵̢̡͎̯̙͇͍̇͊̃̓̚͜ͅd̸̟̤̼̲̈́̎̑͜ͅȩ̸͓̝̘̙͉̼̺̖̳͓̩̽̕ͅn̴͈̈̃̿͝ | 1̴̛͈̣̲̹͗̾͂͆̒̓͛̋͝9̵̨̢̨̻̲̬͕̲͔͖̘̀̿͝ͅ8̷̩̹̣̦̙͖͚̞̮́̉̑̓̉͑̈̾́͊̀̽͛͘̚2̵̡̘̠̼͙̅̇͛̽͒̀̄̾́̋̎͐͛͝ | T̷̢̟̙̥̬̰͎͚͈͕̬͆̋͊͛̂̓̈́͊̌̀͆̅̐͘͝ȟ̴̛̹̝͕͒͗è̵̛̩͇͎̤̪͍͎̳̺͔̖̝͖͊̏̀̽͝ ̵͕͇͌͌́͛̑̏͊̈̔̿̚̕͠͝N̴̤̥̖̠͍̻̤̣͈̩̞̾̍̉͐͋̇̈̈́̓̈́̚ͅu̵̲̹̙̦̞̎̏͗͋̌͐̈́͘͜͝͝m̶̡̙̖̳̖͇̻̰̼̝̖̎̈̈̄́̀̽̈́͘͜͝b̸̡̙͚̙̮̀̀̅́̔́̿̑͆̂͒̕è̷̫͕̗̰̌̈́̏͗͆͂r̶̡̢̨̛̛̙̖̲͔̥̲͕̈́̀͆̀̅̀̔̃̿̉̽͝͝ ̵̨͍͎͈̹̺̟̠̪̼̟̟͔̜̆̈́̈́o̶̡̧̯̠̜̤͊̒̀͆̒̀̋̅̽̕͜͝ͅf̸͓̥̻͚̘̹͈͉̱̆̅̊̿͑͛́͆̽̋͘͜͜ ̶̣̭͙̯͇̦͂̋͆͆̕ţ̴̡̨̭̭̺̣̲̤͎̩̮̮̥̿́̔́̂͂h̵͉̤͛͊͛͐͒͒ė̶̜̰͓̤̼̖̜̣͎̫̑̍̌́̂̈̌͆̍ ̴̘̞̖̳͕̳͑̀̆̑͜B̷̨͈̹̣̘̰͕͉̰̹͗̔ȩ̷̡̠̙̖̱̜̲̤͚̼͓̠͛̾̓͆̅̒͂̅̀̿͘͘ạ̶̢̨̮̩͇͚͓̀̄̐̈́̇̇͊̄̾̕͝͝s̵̡̛͚̭̞͌̋̐̑͑̓̒̋͊͊͌̈̎̚ṱ̴̫̤̩͂͒̅̋̓̓̿̅̈́̎ | I̴̢̦̠͈̊̆͌͝͝ͅn̶̛͈̺̜͇̲̭͓͉̎̽̓̊̈̈́̾̔́̽̇͘v̷͈̘̞̬̼̲̍͊͊̋̓̕ą̷̰͙͙̖̖̤̬͙̃d̷̠̀́̓͆̽̽̽̓͘ȩ̵̤̱͓̫̻̫̯̪̎͌̇̆̄̓ͅr̴̗̹̪̬̘̪̝̰͆̒͆̋̃̃̏̈͑̅͝ş̴͎̭̻͔̘͈͉̟̻͈̯̩͓̔̐ |
forAll { (cmds: List[Command]) => cmds.exists { cmd => db.execute(cmd) notCorrupt(db) }}
artist |
year |
album |
name |
---|---|---|---|
İ̵̺͝ṛ̸̣͕̐͜o̴̢̎̿̓̌n̸̥͙̬̣̾́͛̾̌͘ͅ ̶̻͂M̷̗̣̠̠̎̀ȧ̸̛͔͇̐͘į̵̗̞̩̯̫̇̔̾̋̕͝d̵̟͓͆̅̇̋̐̚ͅe̷̯̪̙̼̩̩͐n̴̛̗̟͈͇̖̎̈̕ | 1̶͍͓̣̔̍́̒̒̅͘͜9̷̬̖̹̗̻͍̋͗̈́͠8̶͓̫̹̹̍2̸̨̲̝̏͌ | T̸̜̟͕̩̘̃̇͂͠h̶̦̓͋̇͝e̴̢̝̱̦͎͗͂̅̓͜ͅ ̶̝̬͠͝Ǹ̵̛̘̺̯̃̈́̍ù̷̱̖m̷̗͙̱̥͇̹͑̎̂͊̈́́̌b̸̢̦̪̽̅̂̑e̴̤̫̝̎̈́̇r̵͇̥̃̃̈͋̎̋͗͜ ̴͇̖̼͙̥̲̹̄̀ò̷͉̠̒f̶̲͇̳͛̔̃̽ ̸͍̉̚͝t̶̼̗̬̞̣̂͗͠͠͝h̴̰͒̾̑͐́͝ě̷̠̤͎̳͍̿͆́̕͝ ̸̭̬̊̐̾̍B̷̨̑é̴̡̟͔͖̏̃̔̓͝͠ą̷͉̫͇̫̈́̍̄́̃s̵͍̀̅͂͂͑̌ẗ̷̡̪̙͉͔́͑͗̇̋̑ | C̵͚̣̬̠̞̝̰̐̍̃h̷̥͛͂͋̚̚ï̴̤l̴͉̳̘̝͖̤͋͝d̴̢̲̫̯͙̺̮́̈́̕r̸̢̗̥͇̻͓͗̋̆́ȇ̸̲̉̆n̵̞̙͎̠̲͕̭̅̃̉̂ ̵͔̦͙̯̎͂̑̚͝õ̷̳̱͈̻̤̠̫̽̓̑̊͒f̸̦͋ͅ ̴̹̖̌ṫ̷̻̼͖͗̉̀̑h̴̹͎̰̬̟͊̍ͅe̸̤̱͛́͑ ̸̞̾͊͠D̵̢̜̬̳̍̑͛̄͆̀̅a̴͙̼̤̤͓͇̟̒̈́͋m̷̡̞̬̞̬͆̔̿n̴̨̢̖͉͓̥̂̄͘ë̴̬͚͎̭̭ͅd̸̢͕̼̗̠̂ |
Ì̷̧̺͓͕̘͓̯̗̬͈̤̗̝̰͜ȓ̵̨̜̟̱̘̟̬̙̯̱͍̩̭̈̆̅̍̌̿́̈́́̚͜͝ͅo̴̡͗͗͛̑̿̾͒͂̎̆n̶͖̳͖͉̗͕̱͔̱̖̫̽̎͜ͅ ̸̢̨̛͇͚͔̘̦̘̱̮̖̿͑̒̉̽̎́̑̚̚̕M̷̜͖̊͗̅̆̏̈́͛̍̂̉́̃̚̕͝ả̷̡̛̫͔̳̞̻͔͉̜̍̅̈́̆͛͒̋̑͠i̵̢̡͎̯̙͇͍̇͊̃̓̚͜ͅd̸̟̤̼̲̈́̎̑͜ͅȩ̸͓̝̘̙͉̼̺̖̳͓̩̽̕ͅn̴͈̈̃̿͝ | 1̴̛͈̣̲̹͗̾͂͆̒̓͛̋͝9̵̨̢̨̻̲̬͕̲͔͖̘̀̿͝ͅ8̷̩̹̣̦̙͖͚̞̮́̉̑̓̉͑̈̾́͊̀̽͛͘̚2̵̡̘̠̼͙̅̇͛̽͒̀̄̾́̋̎͐͛͝ | T̷̢̟̙̥̬̰͎͚͈͕̬͆̋͊͛̂̓̈́͊̌̀͆̅̐͘͝ȟ̴̛̹̝͕͒͗è̵̛̩͇͎̤̪͍͎̳̺͔̖̝͖͊̏̀̽͝ ̵͕͇͌͌́͛̑̏͊̈̔̿̚̕͠͝N̴̤̥̖̠͍̻̤̣͈̩̞̾̍̉͐͋̇̈̈́̓̈́̚ͅu̵̲̹̙̦̞̎̏͗͋̌͐̈́͘͜͝͝m̶̡̙̖̳̖͇̻̰̼̝̖̎̈̈̄́̀̽̈́͘͜͝b̸̡̙͚̙̮̀̀̅́̔́̿̑͆̂͒̕è̷̫͕̗̰̌̈́̏͗͆͂r̶̡̢̨̛̛̙̖̲͔̥̲͕̈́̀͆̀̅̀̔̃̿̉̽͝͝ ̵̨͍͎͈̹̺̟̠̪̼̟̟͔̜̆̈́̈́o̶̡̧̯̠̜̤͊̒̀͆̒̀̋̅̽̕͜͝ͅf̸͓̥̻͚̘̹͈͉̱̆̅̊̿͑͛́͆̽̋͘͜͜ ̶̣̭͙̯͇̦͂̋͆͆̕ţ̴̡̨̭̭̺̣̲̤͎̩̮̮̥̿́̔́̂͂h̵͉̤͛͊͛͐͒͒ė̶̜̰͓̤̼̖̜̣͎̫̑̍̌́̂̈̌͆̍ ̴̘̞̖̳͕̳͑̀̆̑͜B̷̨͈̹̣̘̰͕͉̰̹͗̔ȩ̷̡̠̙̖̱̜̲̤͚̼͓̠͛̾̓͆̅̒͂̅̀̿͘͘ạ̶̢̨̮̩͇͚͓̀̄̐̈́̇̇͊̄̾̕͝͝s̵̡̛͚̭̞͌̋̐̑͑̓̒̋͊͊͌̈̎̚ṱ̴̫̤̩͂͒̅̋̓̓̿̅̈́̎ | I̴̢̦̠͈̊̆͌͝͝ͅn̶̛͈̺̜͇̲̭͓͉̎̽̓̊̈̈́̾̔́̽̇͘v̷͈̘̞̬̼̲̍͊͊̋̓̕ą̷̰͙͙̖̖̤̬͙̃d̷̠̀́̓͆̽̽̽̓͘ȩ̵̤̱͓̫̻̫̯̪̎͌̇̆̄̓ͅr̴̗̹̪̬̘̪̝̰͆̒͆̋̃̃̏̈͑̅͝ş̴͎̭̻͔̘͈͉̟̻͈̯̩͓̔̐ |
forAll { (cmds: List[Command]) => cmds.exists { cmd => db.execute(cmd) notCorrupt(db) }}
val propSafeFizzBuzz = forAll { (i: Int) => Try(fizzBuzz(i)).isSuccess}
val propSafeFizzBuzz = forAll { (i: Int) => Try(fizzBuzz(i)).isSuccess}
val propSafeFizzBuzz = forAll { (i: Int) => Try(fizzBuzz(i)).isSuccess}
propSafeFizzBuzz.check()
propSafeFizzBuzz.check()// + OK, passed 100 tests.
forAll { (i: Int) => mult3(i) == mult3(-i)}
forAll { (i: Int) => mult3(i) == mult3(-i)}
forAll { (i: Int) => mult3(i) == mult3(-i)}
forAll { (i: Int) => mult3(i) == mult3(-i)}
forAll { (i: Int) => mult3(i) == mult3(-i)}
Metamorphic testing of RESTful web apis:
3 new unique Spotify bugs.
8 new unique YouTube bugs.
val propStableFizz = forAll { (i: Int) => fizzBuzz(i).contains("Fizz") ==> fizzBuzz(-i).contains("Fizz")}
val propStableFizz = forAll { (i: Int) => fizzBuzz(i).contains("Fizz") ==> fizzBuzz(-i).contains("Fizz")}
val propStableFizz = forAll { (i: Int) => fizzBuzz(i).contains("Fizz") ==> fizzBuzz(-i).contains("Fizz")}
val propStableFizz = forAll { (i: Int) => fizzBuzz(i).contains("Fizz") ==> fizzBuzz(-i).contains("Fizz")}
val propStableFizz = forAll { (i: Int) => fizzBuzz(i).contains("Fizz") ==> fizzBuzz(-i).contains("Fizz")}
val propStableFizz = forAll { (i: Int) => fizzBuzz(i).contains("Fizz") ==> fizzBuzz(-i).contains("Fizz")}
val propStableFizz = forAll { (i: Int) => fizzBuzz(i).contains("Fizz") ==> fizzBuzz(-i).contains("Fizz")}
propStableFizz.check()
propStableFizz.check()// ! Falsified after 1 passed tests.// > ARG_0: -1// > ARG_0_ORIGINAL: -67
fizzBuzz
def mult3(i: Int) = !(i % 3 > 0)def mult5(i: Int) = !(i % 5 > 0)def fizzBuzz(i: Int) = if mult3(i) then if mult5(i) then "FizzBuzz" else "Fizz" else if mult5(i) then "Buzz" else i.toString
fizzBuzz
def mult3(i: Int) = i % 3 == 0def mult5(i: Int) = i % 5 == 0def fizzBuzz(i: Int) = if mult3(i) then if mult5(i) then "FizzBuzz" else "Fizz" else if mult5(i) then "Buzz" else i.toString
fizzBuzz
propStableFizz.check()
fizzBuzz
propStableFizz.check()// + OK, passed 100 tests.
class FizzBuzzProps extends Properties("FizzBuzz"): property("validity") = forAll { (i: Int) => fizzBuzz(i) in Set(i.toString, "Fizz", "Buzz", "FizzBuzz") } property("involutivity") = forAll { (i: Int) => !(mult3(i) || mult5(i)) ==> (fizzBuzz(i).toInt == i) } property("metamorphic") = forAll { (i: Int) => fizzBuzz(i).contains("Fizz") ==> fizzBuzz(-i).contains("Fizz") } property("invariant") = forAll { (i: Int) => Try(fizzBuzz(i)).isSuccess }
class FizzBuzzProps extends Properties("FizzBuzz"): property("validity") = forAll { (i: Int) => fizzBuzz(i) in Set(i.toString, "Fizz", "Buzz", "FizzBuzz") } property("involutivity") = forAll { (i: Int) => !(mult3(i) || mult5(i)) ==> (fizzBuzz(i).toInt == i) } property("metamorphic") = forAll { (i: Int) => fizzBuzz(i).contains("Fizz") ==> fizzBuzz(-i).contains("Fizz") } property("invariant") = forAll { (i: Int) => Try(fizzBuzz(i)).isSuccess }
class FizzBuzzProps extends Properties("FizzBuzz"): property("validity") = forAll { (i: Int) => fizzBuzz(i) in Set(i.toString, "Fizz", "Buzz", "FizzBuzz") } property("involutivity") = forAll { (i: Int) => !(mult3(i) || mult5(i)) ==> (fizzBuzz(i).toInt == i) } property("metamorphic") = forAll { (i: Int) => fizzBuzz(i).contains("Fizz") ==> fizzBuzz(-i).contains("Fizz") } property("invariant") = forAll { (i: Int) => Try(fizzBuzz(i)).isSuccess }
class FizzBuzzProps extends Properties("FizzBuzz"): property("validity") = forAll { (i: Int) => fizzBuzz(i) in Set(i.toString, "Fizz", "Buzz", "FizzBuzz") } property("involutivity") = forAll { (i: Int) => !(mult3(i) || mult5(i)) ==> (fizzBuzz(i).toInt == i) } property("metamorphic") = forAll { (i: Int) => fizzBuzz(i).contains("Fizz") ==> fizzBuzz(-i).contains("Fizz") } property("invariant") = forAll { (i: Int) => Try(fizzBuzz(i)).isSuccess }
class FizzBuzzProps extends Properties("FizzBuzz"): property("validity") = forAll { (i: Int) => fizzBuzz(i) in Set(i.toString, "Fizz", "Buzz", "FizzBuzz") } property("involutivity") = forAll { (i: Int) => !(mult3(i) || mult5(i)) ==> (fizzBuzz(i).toInt == i) } property("metamorphic") = forAll { (i: Int) => fizzBuzz(i).contains("Fizz") ==> fizzBuzz(-i).contains("Fizz") } property("invariant") = forAll { (i: Int) => Try(fizzBuzz(i)).isSuccess }
new FizzBuzzProps().check()
new FizzBuzzProps().check()// + FizzBuzz.validity: OK, passed 100 tests.// + FizzBuzz.involutivity: OK, passed 100 tests.// + FizzBuzz.metamorphic: OK, passed 100 tests.// + FizzBuzz.invariant: OK, passed 100 tests.
def fizzBuzz(i: Int) = if mult3(i) then if mult5(i) then "FizzBuzz" else "Fizz" else if mult5(i) then "Buzz" else i.toString
def fizzBuzz(i: Int) = if mult3(i) then if mult5(i) then "FizzBuzz" else "Buzz" else if mult5(i) then "Fizz" else i.toString
new FizzBuzzProps().check()
new FizzBuzzProps().check()// + FizzBuzz.validity: OK, passed 100 tests.// + FizzBuzz.involutivity: OK, passed 100 tests.// + FizzBuzz.metamorphic: OK, passed 100 tests.// + FizzBuzz.invariant: OK, passed 100 tests.
new FizzBuzzProps().check()// + FizzBuzz.validity: OK, passed 100 tests.// + FizzBuzz.involutivity: OK, passed 100 tests.// + FizzBuzz.metamorphic: OK, passed 100 tests.// + FizzBuzz.invariant: OK, passed 100 tests.
val propFizz = forAll { (i: Int) => fizzBuzz(i * 3).contains("Fizz")}
val propFizz = forAll { (i: Int) => fizzBuzz(i * 3).contains("Fizz")}
val propFizz = forAll { (i: Int) => fizzBuzz(i * 3).contains("Fizz")}
val propFizz = forAll { (i: Int) => fizzBuzz(i * 3).contains("Fizz")}
val propFizz = forAll { (i: Int) => fizzBuzz(i * 3).contains("Fizz")}
propFizz.check()
propFizz.check()// ! Falsified after 0 passed tests.// > ARG_0: 1// > ARG_0_ORIGINAL: 34
Property-based testing is:
Property-based testing is:
Property-based testing is:
very good at the test case generation problem.
good at the oracle problem.
Property-based testing is:
very good at the test case generation problem.
good at the oracle problem.
hard to get the hang of.
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
val propFizzBuzz3 = fizzBuzz(3) == "Fizz"
val propFizzBuzz3 = fizzBuzz(3) == "Fizz"
val propFizzBuzz3 = forAll(const(3)) { i => fizzBuzz(3) == "Fizz" }
val propFizzBuzz3 = forAll(const(3)) { i => fizzBuzz(3) == "Fizz" }
val propFizzBuzz3 = forAll(const(3)) { i => fizzBuzz(3) == "Fizz" }
val propFizzBuzz3 = forAll(const(3)) { i => fizzBuzz(3) == "Fizz" }
val propFizzBuzz3 = forAll(const(3)) { i => fizzBuzz(i) == "Fizz" }
val propFizzBuzz3 = forAll(const(3)) { i => fizzBuzz(i) == "Fizz" }
val genMult3: Gen[Int] = arbitrary[Int] .map(_ * 3) .filter(_ % 5 != 0)
val genMult3: Gen[Int] = arbitrary[Int] .map(_ * 3) .filter(_ % 5 != 0)
val genMult3: Gen[Int] = arbitrary[Int] .map(_ * 3) .filter(_ % 5 != 0)
val propFizzBuzz3 = forAll(const(3)) { i => fizzBuzz(i) == "Fizz" }
val propFizzBuzz3 = forAll(genMult3) { i => fizzBuzz(i) == "Fizz" }
val propFizzBuzz3 = forAll(genMult3) { i => fizzBuzz(i) == "Fizz" }
val propFizzBuzz3 = forAll(genMult3) { i => fizzBuzz(i) == "Fizz" }
val propFizzBuzz3 = forAll(genMult3) { i => fizzBuzz(i) == "Fizz" }
def propFizzBuzz(gen: Gen[Int]) = forAll(genMult3) { i => fizzBuzz(i) == "Fizz" }
def propFizzBuzz(gen: Gen[Int]) = forAll(genMult3) { i => fizzBuzz(i) == "Fizz" }
def propFizzBuzz(gen: Gen[Int]) = forAll(gen) { i => fizzBuzz(i) == "Fizz" }
def propFizzBuzz(gen: Gen[Int], expected: String) = forAll(gen) { i => fizzBuzz(i) == "Fizz" }
def propFizzBuzz(gen: Gen[Int], expected: String) = forAll(gen) { i => fizzBuzz(i) == "Fizz" }
def propFizzBuzz(gen: Gen[Int], expected: String) = forAll(gen) { i => fizzBuzz(i) == expected }
val propFizzBuzz3 = forAll(genMult3) { i => fizzBuzz(i) == "Fizz" }
val propFizzBuzz3 = propFizzBuzz( gen = genMult3, expected = "Fizz" )
val propFizzBuzz3 = propFizzBuzz( gen = genMult3, expected = "Fizz" )
val propFizzBuzz3 = propFizzBuzz( gen = genMult3, expected = "Fizz" )
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
val genMult5: Gen[Int] = arbitrary[Int] .map(_ * 5) .filter(_ % 3 != 0)
val genMult5: Gen[Int] = arbitrary[Int] .map(_ * 5) .filter(_ % 3 != 0)
val genMult5: Gen[Int] = arbitrary[Int] .map(_ * 5) .filter(_ % 3 != 0)
val propFizzBuzz5 = propFizzBuzz( gen = genMult5, expected = "Buzz" )
val propFizzBuzz5 = propFizzBuzz( gen = genMult5, expected = "Buzz" )
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
val genMultNone: Gen[Int] = arbitrary[Int] .filter(_ % 5 != 0) .filter(_ % 3 != 0)
val genMultNone: Gen[Int] = arbitrary[Int] .filter(_ % 5 != 0) .filter(_ % 3 != 0)
val genMultNone: Gen[Int] = arbitrary[Int] .filter(_ % 5 != 0) .filter(_ % 3 != 0)
val propFizzBuzzNone = propFizzBuzz( gen = genMultNone, expected = ??? )
val propFizzBuzzNone = propFizzBuzz( gen = genMultNone, expected = ??? )
def propFizzBuzz(gen: Gen[Int], expected: String) = forAll(gen) { i => fizzBuzz(i) == expected }
def propFizzBuzz(gen: Gen[Int], oracle: Int => String) = forAll(gen) { i => fizzBuzz(i) == oracle(i) }
val propFizzBuzzNone = propFizzBuzz( gen = genMultNone, expected = ??? )
val propFizzBuzzNone = propFizzBuzz( gen = genMultNone, oracle = _.toString )
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
class FizzBuzzSuite extends AnyFunSuite: test("n multiple of 3 outputs Fizz") { assert(fizzBuzz(3) == "Fizz") } test("n multiple of 5 outputs Buzz") { assert(fizzBuzz(5) == "Buzz") } test("n multiple of neither 3 or 5 outputs n") { assert(fizzBuzz(7) == "7") } test("n multiple of 3 and 5 outputs FizzBuzz") { assert(fizzBuzz(15) == "FizzBuzz") }
val genMult15: Gen[Int] = arbitrary[Int]. map(_ * 3 * 5)
val genMult15: Gen[Int] = arbitrary[Int]. map(_ * 3 * 5)
val propFizzBuzz15 = propFizzBuzz( gen = genMult15, oracle = _ => "FizzBuzz" )
val propFizzBuzz15 = propFizzBuzz( gen = genMult15, oracle = _ => "FizzBuzz" )
you don't need to learn a new way to write tests (right away).
you can adapt existing tests with little work.
you don't need to learn a new way to write tests (right away).
you can adapt existing tests with little work.
you will acquire the skills you need as you do so.
Property-based testing:
Property-based testing:
finds more flaws than example-based testing.
doesn't need to be harder than example-based testing.
Property-based testing:
finds more flaws than example-based testing.
doesn't need to be harder than example-based testing.
importantly, is a lot of fun!
def fizzBuzz(i: Int) = if mult3(i) then if mult5(i) then "FizzBuzz" else "Fizz" else if mult5(i) then "Buzz" else i.toString
println(fizzBuzz(5))
println(fizzBuzz(5))
println(fizzBuzz(5))// Buzz
println(fizzBuzz(5))// Buzz
def fizzBuzz(i: Int) = if mult3(i) then if mult5(i) then "FizzBuzz" else "Fizz" else if mult5(i) then "Buzz" else i.toString
def fizzBuzz(i: Int) = if mult3(i) then if mult5(i) then "FizzBuzz" else "Fizz" else if mult5(i) then "Buzz" else i.toString
def fizzBuzz(i: Int) = if mult3(i) then if mult5(i) then "FizzBuzz" else "Fizz" else if mult5(i) then "Buzz" else i.toString
def fizzBuzz(i: Int) = if mult3(i) then "Fizz" else if mult5(i) then "Buzz" else i.toString
def fizzBuzz(i: Int) = if mult3(i) then "Fizz" else if mult5(i) then "Buzz" else i.toString
def fizzBuzz(i: Int) = if mult3(i) then "Zzif" else if mult5(i) then "Buzz" else i.toString
println(fizzBuzz(5))
println(fizzBuzz(5))
println(fizzBuzz(5))// Buzz
println(fizzBuzz(5))// Buzz
println(fizzBuzz(5))// Zzif
println(fizzBuzz(5))// Zzif
Compiler Validation via Equivalence Modulo Inputs:
79 new unique gcc bugs.
68 new unique LLVM bugs.
Compiler Validation via Equivalence Modulo Inputs:
79 new unique gcc bugs.
68 new unique LLVM bugs.
42 new unique scalac bugs.
Metamorphic Testing:
Metamorphic Testing:
Metamorphic Testing:
helps generating test cases when it's too expensive.
helps with the oracle problem.
Metamorphic Testing:
helps generating test cases when it's too expensive.
helps with the oracle problem.
a good word to use when you want to sound smart.
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |