2012-02-22 2 views
6

저는 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 
+2

선언문이 모두 좋으므로 오류가 발생하는 실제 코드를 게시하는 것이 좋습니다. –

+1

Nunit으로 무엇을하고 계십니까? 당신은 어떻게 대답이 도움이 될 것이라고 생각합니까? – manojlds

+0

실제로 F #에 C# 응용 프로그램을 포팅하여 간결함을 확인했습니다. 기존 테스트 하네스 (C#으로 작성)를 사용해도 문제없이 사용할 수 있습니다. 대부분의 다른 테스트는 통과하지만이 부분 만 실패합니다. F # 코드를 테스트하는 다른 방법이 있습니까? –

답변

6

가 실제로 막연하게 CLR 어떤 대상에 열거의 전체 배열 리터럴을 만드는 방법에 대해 몇 가지 버그를 기억 플랫폼에서는 5 이상이있는 경우 잘못된 코드가 생성되었거나 무언가 있습니다. 아마 그걸 때리는거야? x64 및 CLR2를 타겟팅하고 있습니까? 배열 리터럴을 피함으로써 버그를 해결할 수 있습니다. 목록을 작성한 다음 List.ToArray으로 전화하십시오.

+0

굉장합니다. 그 버그로 인한 것인지 여부를 확인할 방법이 없지만 그럴 것 같아요. 목록을 사용할 때 아무런 문제가 없습니다. 무리 감사! –

+0

이 버그가 이미 해결 된 경우 Kow합니까? – Rustam

관련 문제