public void TestDecodeAndResolution() { SetUp(); builder.Name("scalar"); InitSe(); double resolution = se.GetResolution(); StringBuilder @out = new StringBuilder(); for (double v = se.GetMinVal(); v < se.GetMaxVal(); v += (resolution / 4.0d)) { int[] output = se.Encode(v); DecodeResult decodedInFor = (DecodeResult)se.Decode(output, ""); Console.WriteLine(@out.Append("decoding ").Append(Arrays.ToString(output)).Append(" ("). Append(string.Format("{0}", v)).Append(")=> ").Append(se.DecodedToStr(decodedInFor))); @out.Length = 0; Map <string, RangeList> fieldsMapInFor = decodedInFor.GetFields(); Assert.AreEqual(1, fieldsMapInFor.Count); RangeList ranges = new List <RangeList>(fieldsMapInFor.Values)[0]; Assert.AreEqual(1, ranges.Count); Assert.AreEqual(ranges.GetRange(0).Min(), ranges.GetRange(0).Max(), 0); Assert.IsTrue(ranges.GetRange(0).Min() - v < se.GetResolution()); EncoderResult topDown = se.TopDownCompute(output)[0]; Console.WriteLine("topdown => " + topDown); Assert.IsTrue(Arrays.AreEqual(topDown.GetEncoding(), output)); Assert.IsTrue(Math.Abs(((double)topDown.Get(1)) - v) <= se.GetResolution() / 2); //Test bucket support int[] bucketIndices = se.GetBucketIndices(v); Console.WriteLine("bucket index => " + bucketIndices[0]); topDown = se.GetBucketInfo(bucketIndices)[0]; Assert.IsTrue(Math.Abs(((double)topDown.Get(1)) - v) <= se.GetResolution() / 2); Assert.AreEqual(topDown.Get(1), se.GetBucketValues <double>(typeof(double)).ToArray()[bucketIndices[0]]); Assert.AreEqual(topDown.Get(2), topDown.Get(1)); Assert.IsTrue(Arrays.AreEqual(topDown.GetEncoding(), output)); } // ----------------------------------------------------------------------- // Test the input description generation on a large number, periodic encoder SetUp(); builder.Name("scalar") .W(3) .Radius(1.5) .MinVal(1.0) .MaxVal(8.0) .Periodic(true) .Forced(true); InitSe(); Console.WriteLine("\nTesting periodic encoder decoding, resolution of " + se.GetResolution()); //Test with a "hole" int[] encoded = new[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }; DecodeResult decoded = (DecodeResult)se.Decode(encoded, ""); Map <string, RangeList> fieldsMap = decoded.GetFields(); Assert.AreEqual(1, fieldsMap.Count); Assert.AreEqual(1, decoded.GetRanges("scalar").Count); Assert.AreEqual("7.5, 7.5", decoded.GetRanges("scalar").GetRange(0).ToString()); //Test with something wider than w, and with a hole, and wrapped encoded = new[] { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }; decoded = (DecodeResult)se.Decode(encoded, ""); fieldsMap = decoded.GetFields(); Assert.AreEqual(1, fieldsMap.Count); Assert.AreEqual(2, decoded.GetRanges("scalar").Count); Assert.AreEqual("7.5, 8.0", decoded.GetRanges("scalar").GetRange(0).ToString()); //Test with something wider than w, no hole encoded = new[] { 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; decoded = (DecodeResult)se.Decode(encoded, ""); fieldsMap = decoded.GetFields(); Assert.AreEqual(1, fieldsMap.Count); Assert.AreEqual(1, decoded.GetRanges("scalar").Count); Assert.AreEqual(decoded.GetRanges("scalar").GetRange(0).ToString(), "1.5, 2.5"); //Test with 2 ranges encoded = new[] { 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0 }; decoded = (DecodeResult)se.Decode(encoded, ""); fieldsMap = decoded.GetFields(); Assert.AreEqual(1, fieldsMap.Count); Assert.AreEqual(2, decoded.GetRanges("scalar").Count); Assert.AreEqual(decoded.GetRanges("scalar").GetRange(0).ToString(), "1.5, 1.5"); Assert.AreEqual(decoded.GetRanges("scalar").GetRange(1).ToString(), "5.5, 6.0"); //Test with 2 ranges, 1 of which is narrower than w encoded = new[] { 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0 }; decoded = (DecodeResult)se.Decode(encoded, ""); fieldsMap = decoded.GetFields(); Assert.AreEqual(1, fieldsMap.Count); Assert.AreEqual(2, decoded.GetRanges("scalar").Count); Assert.AreEqual(decoded.GetRanges("scalar").GetRange(0).ToString(), "1.5, 1.5"); Assert.AreEqual(decoded.GetRanges("scalar").GetRange(1).ToString(), "5.5, 6.0"); }