DataPointTest.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. //
  2. // Authors:
  3. // Jonathan Pobst ([email protected])
  4. //
  5. // Copyright (C) 2009 Novell, Inc (http://www.novell.com)
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining
  8. // a copy of this software and associated documentation files (the
  9. // "Software"), to deal in the Software without restriction, including
  10. // without limitation the rights to use, copy, modify, merge, publish,
  11. // distribute, sublicense, and/or sell copies of the Software, and to
  12. // permit persons to whom the Software is furnished to do so, subject to
  13. // the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be
  16. // included in all copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. using System;
  26. using System.Windows.Forms.DataVisualization.Charting;
  27. using NUnit.Framework;
  28. namespace MonoTests.System.Windows.Forms.DataVisualization.Charting
  29. {
  30. [TestFixture]
  31. public class DataPointTest
  32. {
  33. [Test]
  34. public void Constructor1 ()
  35. {
  36. DataPoint dp = new DataPoint ();
  37. Assert.AreEqual (false, dp.IsEmpty, "A1");
  38. Assert.AreEqual ("DataPoint", dp.Name, "A2");
  39. Assert.AreEqual (0, dp.XValue, "A3");
  40. Assert.AreEqual (new double[] { 0.0d }, dp.YValues, "A4");
  41. }
  42. [Test]
  43. public void Constructor2 ()
  44. {
  45. DataPoint dp = new DataPoint (1d, 2d);
  46. Assert.AreEqual (false, dp.IsEmpty, "A1");
  47. Assert.AreEqual ("DataPoint", dp.Name, "A2");
  48. Assert.AreEqual (1d, dp.XValue, "A3");
  49. Assert.AreEqual (new double[] { 2d }, dp.YValues, "A4");
  50. }
  51. [Test]
  52. public void Constructor3 ()
  53. {
  54. DataPoint dp = new DataPoint (1d, new double[] { 2d, 3d });
  55. Assert.AreEqual (false, dp.IsEmpty, "A1");
  56. Assert.AreEqual ("DataPoint", dp.Name, "A2");
  57. Assert.AreEqual (1d, dp.XValue, "A3");
  58. Assert.AreEqual (new double[] { 2d, 3d }, dp.YValues, "A4");
  59. }
  60. [Test]
  61. public void IsEmptyProperty ()
  62. {
  63. DataPoint dp = new DataPoint (1d, 2d);
  64. Assert.AreEqual (false, dp.IsEmpty, "A1");
  65. Assert.AreEqual (1d, dp.XValue, "A2");
  66. Assert.AreEqual (new double[] { 2d }, dp.YValues, "A3");
  67. dp.IsEmpty = true;
  68. Assert.AreEqual (true, dp.IsEmpty, "A4");
  69. Assert.AreEqual (1d, dp.XValue, "A5");
  70. Assert.AreEqual (new double[] { 2d }, dp.YValues, "A6");
  71. dp.XValue = 6d;
  72. dp.YValues = new double[] { 7d };
  73. Assert.AreEqual (true, dp.IsEmpty, "A7");
  74. }
  75. [Test]
  76. public void NameProperty ()
  77. {
  78. DataPoint dp = new DataPoint (1d, 2d);
  79. Assert.AreEqual ("DataPoint", dp.Name, "A1");
  80. dp.Name = "Point";
  81. Assert.AreEqual ("DataPoint", dp.Name, "A2");
  82. }
  83. [Test]
  84. public void XValueProperty ()
  85. {
  86. DataPoint dp = new DataPoint (1d, 2d);
  87. Assert.AreEqual (1d, dp.XValue, "A1");
  88. dp.XValue = 2d;
  89. Assert.AreEqual (2d, dp.XValue, "A2");
  90. }
  91. [Test]
  92. public void YValueProperty ()
  93. {
  94. DataPoint dp = new DataPoint (1d, 2d);
  95. Assert.AreEqual (new double[] { 2d }, dp.YValues, "A1");
  96. dp.YValues = new double[] { 2d, 3d };
  97. Assert.AreEqual (new double[] { 2d, 3d }, dp.YValues, "A2");
  98. }
  99. [Test]
  100. public void CloneMethod ()
  101. {
  102. DataPoint dp = new DataPoint ();
  103. Assert.AreEqual (false, dp.IsEmpty, "A1");
  104. Assert.AreEqual ("DataPoint", dp.Name, "A2");
  105. Assert.AreEqual (0, dp.XValue, "A3");
  106. Assert.AreEqual (new double[] { 0.0d }, dp.YValues, "A4");
  107. DataPoint dp2 = (DataPoint)dp.Clone ();
  108. Assert.AreEqual (false, dp2.IsEmpty, "A5");
  109. Assert.AreEqual ("DataPoint", dp2.Name, "A6");
  110. Assert.AreEqual (0, dp2.XValue, "A7");
  111. Assert.AreEqual (new double[] { 0.0d }, dp2.YValues, "A8");
  112. }
  113. [Test]
  114. public void GetValueByNameMethod ()
  115. {
  116. DataPoint dp = new DataPoint (1d, new double[] { 2d, 3d });
  117. Assert.AreEqual (1d, dp.GetValueByName ("X"), "A1");
  118. Assert.AreEqual (2d, dp.GetValueByName ("Y"), "A2");
  119. Assert.AreEqual (2d, dp.GetValueByName ("Y1"), "A3");
  120. Assert.AreEqual (3d, dp.GetValueByName ("Y2"), "A4");
  121. Assert.AreEqual (1d, dp.GetValueByName ("x"), "A5");
  122. Assert.AreEqual (2d, dp.GetValueByName ("y"), "A6");
  123. Assert.AreEqual (2d, dp.GetValueByName ("y1"), "A7");
  124. Assert.AreEqual (3d, dp.GetValueByName ("y2"), "A8");
  125. }
  126. [Test]
  127. [ExpectedException (typeof (ArgumentException))]
  128. public void GetValueByNameMethodAE ()
  129. {
  130. DataPoint dp = new DataPoint (1d, new double[] { 2d, 3d });
  131. Assert.AreEqual (1d, dp.GetValueByName ("X1"), "A1");
  132. }
  133. [Test]
  134. [ExpectedException (typeof (ArgumentException))]
  135. public void GetValueByNameMethodAE2 ()
  136. {
  137. DataPoint dp = new DataPoint (1d, new double[] { 2d, 3d });
  138. Assert.AreEqual (1d, dp.GetValueByName ("Y4"), "A1");
  139. }
  140. [Test]
  141. [ExpectedException (typeof (ArgumentNullException))]
  142. public void GetValueByNameMethodANE ()
  143. {
  144. DataPoint dp = new DataPoint (1d, new double[] { 2d, 3d });
  145. Assert.AreEqual (1d, dp.GetValueByName (null), "A1");
  146. }
  147. [Test]
  148. [ExpectedException (typeof (ArgumentException))]
  149. public void GetValueByNameMethodAE3 ()
  150. {
  151. DataPoint dp = new DataPoint (1d, new double[] { 2d, 3d });
  152. Assert.AreEqual (1d, dp.GetValueByName (string.Empty), "A1");
  153. }
  154. [Test]
  155. [ExpectedException (typeof (ArgumentException))]
  156. public void GetValueByNameMethodAE4 ()
  157. {
  158. DataPoint dp = new DataPoint (1d, new double[] { 2d, 3d });
  159. Assert.AreEqual (1d, dp.GetValueByName ("Y0"), "A1");
  160. }
  161. }
  162. }