Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created an instance of Arbitrary[String] #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/scala/com/danielasfregola/zucchini/Dictionary.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.danielasfregola.zucchini

import org.scalacheck.{Arbitrary, Gen}

import scala.io.Source

object Dictionary extends App {
@@ -16,6 +18,10 @@ object Dictionary extends App {
texts.flatMap(line => line.split("\\W+"))
}

println(extractUniqueWordsFromTextFile("BaconipSum.txt").mkString(","))
// println(extractUniqueWordsFromTextFile("BaconipSum.txt").mkString(","))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this commented line


val words: Set[String] = extractUniqueWordsFromTextFile("BaconipSum.txt")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this is correct, you should change this so that the file name is given rather than fixed.

Maybe, you could create a class that given a text file, gives you an Arbitrary[String] based on the words in the given file. Your class should also handle corner cases. For example, what would happen if the given file does not exist?

Cheers,
Daniela

val word: Arbitrary[String] = Arbitrary {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! You can also just write Arbitrary(Gen.oneOf(words)) - it's the same, just more compact!

Gen.oneOf(words)
}
}