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

Extending BddDsl for Typed API #956

Merged
merged 7 commits into from
Jul 14, 2014
Merged

Conversation

galarragas
Copy link
Contributor

I created a parallel trait TBddDsl that allow to write tests for code using the Typed API.

An example of the code you can write is:

case class UserInfo(name: String, gender: String, age: Int)
case class EstimatedContribution(name: String, suggestedPensionContributionPerMonth: Double)

class TypedApiTest extends Specification with TBddDsl {

  "A test with a single source" should {

    "accept an operation from working with a single tuple-typed pipe" in {
      Given {
        List(("Joe", "M", 40), ("Sarah", "F", 22))
      } When {
        in: TypedPipe[(String, String, Int)] =>
          in.map[(String, Double)] { person =>
            person match {
              case (name, "M", age) => (name, (1000.0 / (72 - age)).toDouble)
              case (name, _, age) => (name, (1000.0 / (80 - age)).toDouble)
            }
          }
      } Then {
        buffer: mutable.Buffer[(String, Double)] =>
          buffer.toList mustEqual List(("Joe", 1000.0 / 32), ("Sarah", 1000.0 / 58))
      }
    }

    "accept an operation from single case class-typed pipe" in {
      Given {
        List(UserInfo("Joe", "M", 40), UserInfo("Sarah", "F", 22))
      } When {
        in: TypedPipe[UserInfo] =>
          in.map { person =>
            person match {
              case UserInfo(name, "M", age) => EstimatedContribution(name, (1000.0 / (72 - age)))
              case UserInfo(name, _, age) => EstimatedContribution(name, (1000.0 / (80 - age)))
            }
          }
      } Then {
        buffer: mutable.Buffer[EstimatedContribution] =>
          buffer.toList mustEqual List(EstimatedContribution("Joe", 1000.0 / 32), EstimatedContribution("Sarah", 1000.0 / 58))
      }
    }
  }   
}

I added this sample of code to the .md documentation file in the package directory


withUserID
.groupBy(_._2)
.join(withGender.groupBy(_._1))
Copy link
Collaborator

Choose a reason for hiding this comment

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

.withGender.group since this is already key, value form. Similar below.

@johnynek
Copy link
Collaborator

Thanks for updating this code to the typed API.

johnynek added a commit that referenced this pull request Jul 14, 2014
Extending BddDsl for Typed API
@johnynek johnynek merged commit e363e0a into twitter:develop Jul 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants