public bool TestMultDiv() { NcArray ones = new NcArray(NcInt.Instance, new int[] { 10 }).Fill(1); NcArray twos = ones * 2; NcArray threes = twos + 1; NcArray fours = twos * 2; NcArray zeros = ones * 0; Assert.True(threes.Equals(ones * threes)); Assert.True(twos.Equals(fours / twos)); Assert.True(twos.Equals(fours / 2)); try { fours.Div(0); throw new AssertFailedException("Failed to throw DivideByZeroException"); } catch (DivideByZeroException) { } NcArray buf = NcArray.Arange(NcDouble.Instance, 5); buf = buf * 10.0; int[] shape = new int[] { 1, 3, 5, 7 }; NcArray uVector = NcArray.Arange(NcShort.Instance, 1 * 3 * 5 * 7).Reshape(shape); return(true); }
public bool TestCasting() { NcArray a = NcArray.Arange(NcInt.Instance, 2); double b = a.GetDoubleAt(0); Assert.Equals(b, 0.0); return(true); }
public bool TestReshape() { int[] shape = new int[] { 2, 2, 2 }; NcArray array = NcArray.Arange(NcDouble.Instance, 2 * 2 * 2).Reshape(shape); Assert.Equals(array.Shape, shape); array.Reshape(new int[] { 8 }); Assert.Equals(array.Shape, new int[] { 8 }); try { array.GetValueAt(1, 1, 1); throw new AssertFailedException("Failed to throw index bounds exception"); } catch (exceptions.NcInvalidArg) { } return(true); }
public bool TestDefine() { NcFile file = null; try { file = new NcFile(filePath, NcFileMode.replace, NcFileFormat.classic); NcDim timeDim = file.AddDim("time", 20); NcVar timeVar = file.AddVar("time", NcDouble.Instance, timeDim); timeVar.PutAtt("units", "minutes since 2000-01-01 00:00:00"); timeVar.PutAtt("long_name", "Time"); timeVar.CheckData(); NcArray vals = NcArray.Arange(NcDouble.Instance, 20); timeVar.PutVar(vals); Assert.Equals(timeVar.GetAtt("long_name"), "Time"); NcVar data = file.AddVar("data", NcDouble.Instance, timeDim); } finally { file.Close(); } CheckDelete(filePath); return(true); }
public bool TestGroupDefine() { NcFile file = null; NcDim dim; NcVar var; try { file = new NcFile(filePath, NcFileMode.replace, NcFileFormat.classic); file.CheckData(); dim = file.AddDim("dim1", 1); file.CheckData(); var = file.AddVar("var1", NcInt.Instance, dim); file.CheckData(); var.PutAtt("blah", "blah"); file.CheckDefine(); NcArray array = NcArray.Arange(NcInt.Instance, 1); var.PutVar(array); } finally { file.Close(); } CheckDelete(filePath); return(true); }