SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

157 lines
6.9 KiB

4 years ago
  1. using NUnit.Framework;
  2. using System.Collections.Generic;
  3. namespace UnityEngine.XR.ARFoundation
  4. {
  5. [TestFixture]
  6. public class ARLightEstimationDataTestFixture
  7. {
  8. [Test]
  9. public void ARLightEstimationData_TestBrightnessConversion()
  10. {
  11. Dictionary<float, float> brightnessToLumensMapping = new Dictionary<float, float> {
  12. // {brightness (0 -> 1), intensity in lumens (0 -> 2000)}
  13. {0f, 0f},
  14. {-1f, 0f},
  15. {0.25f, 500f},
  16. {0.5f, 1000f},
  17. {0.75f, 1500f},
  18. {1f, 2000f},
  19. {1.3f, 2000f}
  20. };
  21. var obj = new ARLightEstimationData();
  22. foreach (var testPair in brightnessToLumensMapping)
  23. {
  24. // If intensity is not filled, expect it to be converted based on the brightness.
  25. obj.averageIntensityInLumens = null;
  26. obj.averageBrightness = testPair.Key;
  27. Assert.AreEqual(obj.averageIntensityInLumens, testPair.Value, "Conversion from averageBrightness to averageIntensityInLumens failed.");
  28. }
  29. obj.averageBrightness = 0.5f;
  30. obj.averageIntensityInLumens = 5000f;
  31. Assert.AreEqual(obj.averageBrightness, 0.5f, "If averageBrightness is set, no conversion should be performed.");
  32. }
  33. [Test]
  34. public void ARLightEstimationData_TestIntensityConversion()
  35. {
  36. Dictionary<float, float> brightnessToLumensMapping = new Dictionary<float, float> {
  37. // {intensity in lumens (0 -> 2000), brightness (0 -> 1)}
  38. {0f, 0f},
  39. {-100f, 0f},
  40. {500f, 0.25f},
  41. {1000f, 0.5f},
  42. {1500f, 0.75f},
  43. {2000f, 1f},
  44. {2500f, 1f}
  45. };
  46. var obj = new ARLightEstimationData();
  47. foreach (var testPair in brightnessToLumensMapping)
  48. {
  49. // If brightness is not filled, expect it to be converted based on the intensity.
  50. obj.averageIntensityInLumens = testPair.Key;
  51. obj.averageBrightness = null;
  52. Assert.AreEqual(obj.averageBrightness, testPair.Value, "Conversion from averageIntensityInLumens to averageBrightness failed.");
  53. }
  54. obj.averageBrightness = 0.5f;
  55. obj.averageIntensityInLumens = 5000f;
  56. Assert.AreEqual(obj.averageIntensityInLumens, 5000f, "If averageIntensityInLumens is set, no conversion should be performed.");
  57. }
  58. [Test]
  59. public void ARLightEstimationData_TestGetHashCode()
  60. {
  61. var obj1 = new ARLightEstimationData();
  62. var obj2 = new ARLightEstimationData();
  63. obj1.averageIntensityInLumens = 1115f;
  64. obj1.averageBrightness = null;
  65. obj2.averageIntensityInLumens = 1233f;
  66. obj2.averageBrightness = null;
  67. Assert.AreNotEqual(obj1.GetHashCode(), obj2.GetHashCode(), "Hash codes should differ when averageIntensityInLumens is different.");
  68. obj1.averageBrightness = 0.5f;
  69. obj1.averageIntensityInLumens = null;
  70. obj2.averageBrightness = 0.6f;
  71. obj2.averageIntensityInLumens = null;
  72. Assert.AreNotEqual(obj1.GetHashCode(), obj2.GetHashCode(), "Hash codes should differ when averageBrightness is different.");
  73. obj1.averageBrightness = 0.5f;
  74. obj1.averageIntensityInLumens = null;
  75. obj2.averageBrightness = 0.5f;
  76. obj2.averageIntensityInLumens = null;
  77. Assert.AreEqual(obj1.GetHashCode(), obj2.GetHashCode(), "Hash codes should match when averageBrightness is same.");
  78. }
  79. [Test]
  80. public void ARLightEstimationData_TestEquality()
  81. {
  82. var obj1 = new ARLightEstimationData();
  83. var obj2 = new ARLightEstimationData();
  84. Assert.AreEqual(obj1, obj2, "Freshly created ARLightEstimationData objects should match.");
  85. obj1.averageBrightness = 0.1f;
  86. obj2.averageBrightness = 0.5f;
  87. Assert.AreNotEqual(obj1, obj2, "ARLightEstimationData with different averageBrightness values should not match.");
  88. obj1.averageBrightness = 0.5f;
  89. obj2.averageBrightness = 0.5f;
  90. Assert.AreEqual(obj1, obj2, "ARLightEstimationData with same averageBrightness values should match.");
  91. obj1.averageBrightness = null;
  92. obj2.averageBrightness = 0.5f;
  93. Assert.AreNotEqual(obj1, obj2, "ARLightEstimationData with different averageBrightness values should not match.");
  94. obj1.averageIntensityInLumens = 1000;
  95. obj2.averageBrightness = 0.5f;
  96. Assert.AreEqual(obj1, obj2, "ARLightEstimationData with same calculated brightness values should match.");
  97. obj1.averageIntensityInLumens = 2000;
  98. obj2.averageBrightness = 0.5f;
  99. Assert.AreNotEqual(obj1, obj2, "ARLightEstimationData with different calculated brightness values should not match.");
  100. obj1.averageIntensityInLumens = null;
  101. obj1.averageBrightness = null;
  102. obj1.colorCorrection = new Color(1f, 0.5f, 0.5f, 1f);
  103. obj2.averageIntensityInLumens = null;
  104. obj2.averageBrightness = null;
  105. obj2.colorCorrection = new Color(1f, 0.5f, 0.5f, 1f);
  106. Assert.AreEqual(obj1, obj2, "ARLightEstimationData with same color correction should match.");
  107. obj1.averageIntensityInLumens = null;
  108. obj1.averageBrightness = null;
  109. obj1.averageColorTemperature = 5230f;
  110. obj2.averageIntensityInLumens = null;
  111. obj2.averageBrightness = null;
  112. obj2.averageColorTemperature = 5230f;
  113. Assert.AreEqual(obj1, obj2, "ARLightEstimationData with same color temperature should match.");
  114. obj1.averageIntensityInLumens = null;
  115. obj1.averageBrightness = null;
  116. obj1.averageColorTemperature = 5230f;
  117. obj1.colorCorrection = new Color(1f, 0.5f, 0.5f, 1f);
  118. obj2.averageIntensityInLumens = null;
  119. obj2.averageBrightness = null;
  120. obj2.averageColorTemperature = 5230f;
  121. obj2.colorCorrection = new Color(1f, 0.5f, 0.5f, 1f);
  122. Assert.AreEqual(obj1, obj2, "ARLightEstimationData with same properties should match.");
  123. obj1.averageIntensityInLumens = null;
  124. obj1.averageBrightness = null;
  125. obj1.averageColorTemperature = 5230f;
  126. obj1.colorCorrection = new Color(1f, 0.5f, 0.5f, 1f);
  127. obj2.averageIntensityInLumens = 2300;
  128. obj2.averageBrightness = 0.5f;
  129. obj2.averageColorTemperature = 1222f;
  130. obj2.colorCorrection = new Color(1f, 1f, 0.5f, 1f);
  131. Assert.AreNotEqual(obj1, obj2, "ARLightEstimationData with different properties should not match.");
  132. }
  133. }
  134. }