2013-04-30 2 views
0

테스트 케이스 내부에서 암시 적 함수를 호출하려고하는데 이클립스 UI가이를 인식하지 못하는 것 같아 Eclipse를 사용하여 컴파일 오류가 발생합니다. - 빌드 ID : 2.1-M2-20121018-1623-Typesafe Eclipse SDK 버전 : 3.7.2junit 테스트 케이스에서 스칼라의 암시 적 함수를 호출하는 방법은 무엇입니까?

나는 뭔가를 놓친가요? .brokeragePricing 에서

코드

package com.scala.dsl 

object TradeDSL { 
    abstract class Instrument(name: String) { def instrumentName: String } 
    case class Stock(name: String) extends Instrument(name) { 
     override val instrumentName = "EQUITY"; 
    } 
    case class Bond(name: String) extends Instrument(name) { 
     override val instrumentName = "BOND"; 
    } 

    abstract class TransactionType { def value: String} 
    case class Buy() extends TransactionType { 
     override val value = "BUY" 
    } 

    case class Sell() extends TransactionType { 
     override val value = "SELL" 
    } 

    class PricingStrategy(order: Order) { 
     def defaultPricing(): Int = order.quantity * order.price 
     def brokeragePricing(): Int = order.quantity * order.price + 100 

    } 

    implicit def orderPricing(order: Order) = new PricingStrategy(order); 

    case class Order(price: Int = 0, instrument: Instrument = null, quantity: Int = 0, totalValue: Int = 0,trn: TransactionType = null, account: String = null) { 
     def maxUnitPrice(p: Int) = copy(price = p) 
     def to(i: Tuple2[Instrument, Int]) = copy(instrument = i._1, quantity = i._2) 
     def buy(qi: Tuple2[Int, Instrument]) = copy(instrument = qi._2, quantity = qi._1, trn = Buy()) 
     def sell(qi: Tuple2[Int, Instrument]) = copy(instrument = qi._2, quantity = qi._1, trn = Sell()) 
     def using(pricing: (Int, Int) => Int) = { 
      copy(totalValue = pricing(quantity, price)) 
     } 
     def forAccount(a: String)(implicit pricing: (Int,Int) => Int) = { 
     copy(account = a, totalValue = pricing(quantity,price)) 
     } 

    } 
} 

테스트 케이스

import org.scalatest.FunSuite 
import org.junit.runner.RunWith 
import org.scalatest.junit.JUnitRunner 
import com.scala.dsl._ 
import com.scala.dsl.TradeDSL.Bond 
import com.scala.dsl.TradeDSL.Stock 
import com.scala.dsl.TradeDSL.Buy 
import com.scala.dsl.TradeDSL.Sell 
import com.scala.dsl.TradeDSL.Order 

@RunWith(classOf[JUnitRunner]) 
class TestTradeDSL extends FunSuite { 


    test("Order") { 
    val order1 = new Order() 
     .buy(10, Stock("GOLD")) 
     .maxUnitPrice(25) 
     .brokeragePricing 
    } 

} 

얻기 컴파일 에러가 나는 헛된에서 프로젝트 & 다시 시작 일식을 제외한 모든 청소했습니다.

+0

maxUnitPrice 도움말에 대한 명시 적 반환 유형을 제공합니까? – Dan

답변

0

TradeDSL 개체를 하나씩 가져 오는 중 문제가 발생합니다. 당신은 개체의 모든 요소를 ​​가져 와서 문제를 해결할 수 있습니다

import com.scala.dsl.TradeDSL._ 

또는 누락 된 요소를 가져 와서

:

import com.scala.dsl.TradeDSL.orderPricing 
관련 문제