2016-09-28 1 views
0
나는 다음과 같은 기능 (지금 예를 들면 fixture1 등 그들이 맨 아래에있는 일부 종속 무시)를 사용하여 내 테스트를 정의하고 싶습니다

:스칼라에서 함수 인수를 연결하는 방법은 무엇입니까?

을 :

multiTest("my test name", fixture1) { case (x: Double, y: Int, z: String) => 
    // test body 
} 

multiTest는 다음과 같이 정의 FunSpecLike 서브 클래스 내 기지에 정의를

def multiTest(testName: String, fixture: FixtureTable)(fun: => Unit)(implicit pos: source.Position): Unit = { 
    val heading = fixture.heading 
    fixture.values.foreach { tuple => 
     it(autoGenerateDesc(heading, tuple)) { 
      fun tuple // <<<<<< how can I pass the tuple to the definition above? 
     } 
    } 
} 

어떻게 튜플을 함수에 푸시 할 수 있습니까?

누락 된 조각 중 일부는

은 다음과 같습니다

case class FixtureTable(heading: Map[String, String], values: Seq[Any]) 
// tableFor generates the permutations of all paramater values 
val fixture1 : FixtureTable = tableFor(
    ("x", List(1e-1, 1e-2)), 
    ("y", List(1, 2, 3)), 
    ("z", List("a", "b"))) 
+0

이 질문에 대한 답변이 있습니까? http://stackoverflow.com/questions/1987820/how-to-apply-a-function-to-a-tuple –

+0

확실하지 않은 답변을 제공 할 수 있습니까? –

답변

1

그대로, 당신은 할 수 없습니다. multitest

def multiTest(testName: String, fixture: FixtureTable)(fun: Any => Unit)(implicit pos: source.Position): Unit = { 
    val heading = fixture.heading 
    fixture.values.foreach { tuple => 
     it(autoGenerateDesc(heading, tuple)) { 
      fun(tuple) 
     } 
    } 
} 

에 또는

case class FixtureTable[A](heading: Map[String, String], values: Seq[A]) 
def multiTest[A](testName: String, fixture: FixtureTable[A])(fun: A => Unit)(implicit pos: source.Position): Unit = { 
    val heading = fixture.heading 
    fixture.values.foreach { tuple => 
     it(autoGenerateDesc(heading, tuple)) { 
      fun(tuple) 
     } 
    } 
} 

더 나은 변경하지만,이 경우의 tableFor 함수를 작성하기 어렵게 될 것이다.

+0

훌륭합니다, 정말 고마워요! –