// -------------------------------------------------------------------------------------------------------------------- // // Copyright (c) 2014 OxyPlot contributors // // // Provides unit tests for the class. // // -------------------------------------------------------------------------------------------------------------------- namespace OxyPlot.Tests { using System; using System.Globalization; using NUnit.Framework; using OxyPlot.Axes; /// /// Provides unit tests for the class. /// [TestFixture] public class LinearAxisTests { /// /// Tests the method. /// public new class GetHashCode { /// /// Given two axes with identical content, verify that the hash codes are different. /// [Test] public void TwoEqualAxes() { var axis1 = new LinearAxis(); var axis2 = new LinearAxis(); Assert.IsTrue(axis1.GetHashCode() != axis2.GetHashCode()); } } /// /// Tests the property. /// public class FormatAsFractions { /// /// Given 0, the FormatValue method should return 0. /// [Test] public void FormatAsFractionsZero() { var axis = new LinearAxis { FormatAsFractions = true, FractionUnit = Math.PI, FractionUnitSymbol = "π" }; Assert.AreEqual("0", axis.FormatValue(0)); } /// /// Given PI/2, the FormatValue method should return π/2. /// [Test] public void FormatAsFractionsPiHalf() { var axis = new LinearAxis { FormatAsFractions = true, FractionUnit = Math.PI, FractionUnitSymbol = "π" }; Assert.AreEqual("π/2", axis.FormatValue(0.5 * Math.PI)); } /// /// Given 2*PI, the FormatValue method should return 2π. /// [Test] public void FormatAsFractionsTwoPi() { var axis = new LinearAxis { FormatAsFractions = true, FractionUnit = Math.PI, FractionUnitSymbol = "π" }; Assert.AreEqual("2π", axis.FormatValue(2 * Math.PI)); } /// /// Given 3/2*PI, the FormatValue method should return 3π/2. /// [Test] public void FormatAsFractionsThreeHalfPi() { var axis = new LinearAxis { FormatAsFractions = true, FractionUnit = Math.PI, FractionUnitSymbol = "π" }; Assert.AreEqual("3π/2", axis.FormatValue(3d / 2 * Math.PI)); } /// /// Given 4 and a format string, the FormatValue method should return 1.273π. /// [Test] public void FormatAsFractionsWithStringFormat() { var model = new PlotModel { Culture = CultureInfo.InvariantCulture }; var axis = new LinearAxis { FormatAsFractions = true, FractionUnit = Math.PI, FractionUnitSymbol = "π", StringFormat = "0.###" }; model.Axes.Add(axis); ((IPlotModel)model).Update(true); Assert.AreEqual("1.273π", axis.FormatValue(4)); } } } }