Soy nuevo en F #, así que probablemente me esté perdiendo algo trivial, pero aquí va.F # Array instancia con 5 elementos pero no con 6
Esto funciona -
let monthsWith31Days = [| MonthType.January;
MonthType.March;
MonthType.May;
MonthType.July;
MonthType.December |]
Pero esto no
let monthsWith31Days = [| MonthType.January;
MonthType.March;
MonthType.May;
MonthType.July;
MonthType.August;
MonthType.December |]
Lo que he notado es que no es el contenido en sí, pero el número de artículos que importan (incluso si cambio los artículos reales usados). El problema comienza cuando el número de elementos superior a 5.
Este es el error que consigo cuando corro mis pruebas NUnit -
System.ArgumentException: Valor no está dentro del rango esperado.
¿Alguna idea de lo que me estoy perdiendo?
Editar:
definición de tipo entero (dos tipos están relacionados de manera mostrando tanto aquí) -
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
Sería bueno publicar el código real que causa el error ya que ambas declaraciones parecen correctas –
¿Qué estás haciendo con Nunit? ¿Cómo crees que solo el error te ayudará a obtener una respuesta? – manojlds
En realidad estoy portando una aplicación C# a F # para ver qué tan concisa se vuelve - puedo usar el arnés de prueba existente (escrito en C#) sin ningún problema (pasan la mayoría de las pruebas, esta es la única área que falla). ¿Hay alguna otra forma de probar el código F #? –