저는 F #에 익숙하지 않으므로 사소한 것이 빠졌지 만 여기에 있습니다.F # 배열은 5 개의 항목으로 인스턴스화하지만 6은 포함하지 않습니다.
이 작동 -
let monthsWith31Days = [| MonthType.January;
MonthType.March;
MonthType.May;
MonthType.July;
MonthType.December |]
을하지만이되지
let monthsWith31Days = [| MonthType.January;
MonthType.March;
MonthType.May;
MonthType.July;
MonthType.August;
MonthType.December |]
내가 주목 한 것은 그 내용 자체가없는 점이다 않지만, 내가 변경하는 경우에도 (중요 항목의 수 실제 사용 된 항목). 값이 예상 범위에 해당하지 않습니다
System.ArgumentException이 - 항목 수는 5
를 초과 할 때 문제가이 내가 내 NUnit과 테스트를 실행할 때 내가 오류입니다 시작합니다.
내가 누락 된 아이디어가 있습니까?
편집 : 전체 유형 정의
을 (두 종류가 그렇게 모두 여기에서 보여주는 관련) -
type public Month(monthType:MonthType, year:Year) =
member public this.Year
with get() = year
member public this.MonthType
with get() = monthType
member public this.GetDaysCount() =
let monthsWith31Days = [| MonthType.January;
MonthType.March;
MonthType.May;
MonthType.July;
MonthType.August;
MonthType.December |]
let has31 = monthsWith31Days |> Array.filter(fun n -> (int)n = (int)this.monthType) |> Array.length
if (has31 > 0)
then 31
// else if (this.MonthType = MonthType.February)
// then (if this.Year.Leap then 29
// else 28)
else 30
and public Year(ad:int) =
member public this.AD
with get() = ad
member public this.Months = Enum.GetValues(typeof<MonthType>).Cast().ToArray()
|> Array.map(fun n -> new Month (n, this))
member public this.GetMonth (index:int) =
(this.Months |> Array.filter(fun p-> (int)p.MonthType = index)).First()
member public this.GetMonth (monthName:string) =
let requiredMonthType = Enum.Parse(typeof<MonthType>, monthName) |> unbox<MonthType>
(this.Months |> Array.filter(fun p-> p.MonthType = requiredMonthType)).First()
member public this.Leap =
if this.AD % 400 = 0 then true
else if this.AD % 100 = 0 then false
else if this.AD % 4 = 0 then true
else false
member this.DaysCount = if this.Leap then 366 else 365
선언문이 모두 좋으므로 오류가 발생하는 실제 코드를 게시하는 것이 좋습니다. –
Nunit으로 무엇을하고 계십니까? 당신은 어떻게 대답이 도움이 될 것이라고 생각합니까? – manojlds
실제로 F #에 C# 응용 프로그램을 포팅하여 간결함을 확인했습니다. 기존 테스트 하네스 (C#으로 작성)를 사용해도 문제없이 사용할 수 있습니다. 대부분의 다른 테스트는 통과하지만이 부분 만 실패합니다. F # 코드를 테스트하는 다른 방법이 있습니까? –