<commit_before>﻿#region License
/**
 * Copyright (c) 2014 <NAME> <<EMAIL>> and other contributors (see CONTRIBUTORS file).
 * Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE
 */
#endregion

using System;

using NUnit.Framework;

using SharpNav;

namespace SharpNavTests
{
	[TestFixture]
	public class MathHelperTests
	{
		[Test]
		public void ClampTest_ValOutOfRange_Success()
		{
			int num = MathHelper.Clamp (3, 6, 10);
			Assert.AreEqual (num, 6);
		}

		[Test]
		public void ClampTest_ValInRange_Success()
		{
			int num = MathHelper.Clamp (7, 4, 10);
			Assert.AreEqual (num, 7);
		}

		[Test]
		public void ClampTest_ValOutOfRangeRef_Success()
		{
			int num_r = 3;
			MathHelper.Clamp (ref num_r, 6, 10);
			Assert.AreEqual (num_r, 6);
		}

		[Test]
		public void ClampTest_ValInRangeRef_Success()
		{
			int num_r = 7;
			MathHelper.Clamp (ref num_r, 6, 10);
			Assert.AreEqual (num_r, 7);
		}

		[Test]
		public void ClampTest_ValInRangeFloat_Success()
		{
			float num = MathHelper.Clamp (7.56f, 6.75f, 10.89f);
			Assert.AreEqual (num, 7.56f);
		}

		[Test]
		public void ClampTest_ValOutOfRangeFloat_Success()
		{
			float num = MathHelper.Clamp (3.89f, 6.75f, 10.89f);
			Assert.AreEqual (num, 6.75f);
		}

		public void ClampTest_ValInRangeFloatRef_Success()
		{
			float num_r = 7.56f;
			MathHelper.Clamp (ref num_r, 6.75f, 10.89f);
			Assert.AreEqual (num_r, 7.56f);
		}

		[Test]
		public void ClampTest_ValOutOfRangeFloatRef_Success()
		{
			float num_r = 3.89f;
			MathHelper.Clamp (ref num_r, 6.75f, 10.89f);
			Assert.AreEqual (num_r, 6.75f);
		}

		[Test]
		public void NextPowerOfTwo_PositiveIntegerInt_Sucess()
		{
			int num = MathHelper.NextPowerOfTwo(5);

			Assert.AreEqual(num, 8);
		}

		[Test]
		public void NextPowerOfTwo_PositiveIntegerUint_Sucess()
		{
			uint num = MathHelper.NextPowerOfTwo((uint)5);

			Assert.AreEqual(num, 8);
		}

		[Test]
		public void NextPowerOfTwo_ZeroInt_Fail()
		{
			int num = MathHelper.NextPowerOfTwo(0);

			//the integer powers of 2 are positive, so the result should be 1
			//but num = 0
			Assert.AreEqual(num, 1);
		}

		[Test]
		public void NextPowerOfTwo_ZeroUint_Fail()
		{
			uint num = MathHelper.NextPowerOfTwo((uint)0);

			//the integer powers of 2 are positive, so the result should be 1
			//but num = 0
			Assert.AreEqual(num, 1);
		}

		[Test]
		public void Log2_PositiveIntegerInt_Success()
		{
			int num = MathHelper.Log2(65);

			Assert.AreEqual(num, 6);
		}
		
		[Test]
		public void Log2_PositiveIntegerUint_Success()
		{
			uint num = MathHelper.Log2((uint)65);

			Assert.AreEqual(num, 6);
		}

		[Test]
		public void Log2_ZeroInt_Fail()
		{
			int num = MathHelper.Log2(0);

			//This test expects 0, even though the result is undefined
			Assert.AreEqual(num, float.NaN);
		}

		[Test]
		public void Log2_ZeroUint_Fail()
		{
			uint num = MathHelper.Log2((uint)0);

			//This test expects 0, even though the result is undefined
			Assert.AreEqual(num, float.NaN);
		}

		[Test]
		public void Log2_NegativeIntegerInt_Fail()
		{
			int num = MathHelper.Log2(-65);

			//This test expects -33, even though the result is undefined
			Assert.AreEqual(num, float.NaN);
		}

		[Test]
		public void PointToSegment2DSquared_NoVectors_Success()
		{
			//point is (0, 0), segment is (0, 1) to (1,0)<commit_msg>Added tests for IsPointInPoly, a MathHelper function<commit_after>﻿#region License
/**
 * Copyright (c) 2014 <NAME> <<EMAIL>> and other contributors (see CONTRIBUTORS file).
 * Licensed under the MIT License - https://raw.github.com/Robmaister/SharpNav/master/LICENSE
 */
#endregion

using System;

using NUnit.Framework;

using SharpNav;

namespace SharpNavTests
{
	[TestFixture]
	public class MathHelperTests
	{
		[Test]
		public void ClampTest_ValOutOfRange_Success()
		{
			int num = MathHelper.Clamp (3, 6, 10);
			Assert.AreEqual (num, 6);
		}

		[Test]
		public void ClampTest_ValInRange_Success()
		{
			int num = MathHelper.Clamp (7, 4, 10);
			Assert.AreEqual (num, 7);
		}

		[Test]
		public void ClampTest_ValOutOfRangeRef_Success()
		{
			int num_r = 3;
			MathHelper.Clamp (ref num_r, 6, 10);
			Assert.AreEqual (num_r, 6);
		}

		[Test]
		public void ClampTest_ValInRangeRef_Success()
		{
			int num_r = 7;
			MathHelper.Clamp (ref num_r, 6, 10);
			Assert.AreEqual (num_r, 7);
		}

		[Test]
		public void ClampTest_ValInRangeFloat_Success()
		{
			float num = MathHelper.Clamp (7.56f, 6.75f, 10.89f);
			Assert.AreEqual (num, 7.56f);
		}

		[Test]
		public void ClampTest_ValOutOfRangeFloat_Success()
		{
			float num = MathHelper.Clamp (3.89f, 6.75f, 10.89f);
			Assert.AreEqual (num, 6.75f);
		}

		public void ClampTest_ValInRangeFloatRef_Success()
		{
			float num_r = 7.56f;
			MathHelper.Clamp (ref num_r, 6.75f, 10.89f);
			Assert.AreEqual (num_r, 7.56f);
		}

		[Test]
		public void ClampTest_ValOutOfRangeFloatRef_Success()
		{
			float num_r = 3.89f;
			MathHelper.Clamp (ref num_r, 6.75f, 10.89f);
			Assert.AreEqual (num_r, 6.75f);
		}

		[Test]
		public void NextPowerOfTwo_PositiveIntegerInt_Sucess()
		{
			int num = MathHelper.NextPowerOfTwo(5);

			Assert.AreEqual(num, 8);
		}

		[Test]
		public void NextPowerOfTwo_PositiveIntegerUint_Sucess()
		{
			uint num = MathHelper.NextPowerOfTwo((uint)5);

			Assert.AreEqual(num, 8);
		}

		[Test]
		public void NextPowerOfTwo_ZeroInt_Fail()
		{
			int num = MathHelper.NextPowerOfTwo(0);

			//the integer powers of 2 are positive, so the result should be 1
			//but num = 0
			Assert.AreEqual(num, 1);
		}

		[Test]
		public void NextPowerOfTwo_ZeroUint_Fail()
		{
			uint num = MathHelper.NextPowerOfTwo((uint)0);

			//the integer powers of 2 are positive, so the result should be 1
			//but num = 0
			Assert.AreEqual(num, 1);
		}

		[Test]
		public void Log2_PositiveIntegerInt_Success()
		{
			int num = MathHelper.Log2(65);

			Assert.AreEqual(num, 6);
		}
		
		[Test]
		public void Log2_PositiveIntegerUint_Success()
		{
			uint num = MathHelper.Log2((uint)65);

			Assert.AreEqual(num, 6);
		}

		[Test]
		public void Log2_ZeroInt_Fail()
		{
			int num = MathHelper.Log2(0);

			//This test expects 0, even though the result is undefined
			Assert.AreEqual(num, float.NaN);
		}

		[Test]
		public void Log2_ZeroUint_Fail()
		{
			uint num = MathHelper.Log2((uint)0);

			//This test expects 0, even though the result is undefined
			Assert.AreEqual(num, float.NaN);
		}

		[Test]
		public void Log2_NegativeIntegerInt_Fail()
		{
			int num = MathHelper.Log2(-65);

			//This test expects -33, even though the result is undefined
			Assert.AreEqual(num, float.NaN);
		}

		[Test]
		public void IsPointInPoly_InternalPoint_Success()
		{
			Vector3 pt = new Vector3(0.0f, 0.0f, 0.5f);

			Vector3[] poly = new Vector3[3];
			poly[0] = new Vector3(0.0f, 0.0f, 1.0f);
			poly[1] = new Vector3(-1.0f, 0.0f, 0.0f);
			poly[2] = new Vector3(1.0f, 0.0f, 0.0f);

			bool isInPoly = MathHelper.IsPointInPoly(pt, poly, poly.Length);

			Assert.IsTrue(isInPoly);
		}

		[Test]
		public void IsPointInPoly_BoundaryPoint_Success()
		{
			Vector3 pt = new Vector3(0.0f, 0.0f, 0.0f);

			Vector3[] poly = new Vector3[3];
			poly[0] = new Vector3(0.0f, 0.0f, 1.0f);
			poly[1] = new Vector3(-1.0f, 0.0f, 0.0f);
			poly[2] = new Vector3(1.0f, 0.0f, 0.0f);

			bool isInPoly = MathHelper.IsPointInPoly(pt, poly, poly.Length);

			Assert.IsTrue(isInPoly);
		}

		[Test]
		public void IsPointInPoly_ExternalPoint_Success()
		{
			Vector3 pt = new Vector3(-1.0f, 0.0f, -1.0f);

			Vector3[] poly = new Vector3[3];
			poly[0] = new Vector3(0.0f, 0.0f, 1.0f);
			poly[1] = new Vector3(-1.0f, 0.0f, 0.0f);
			poly[2] = new Vector3(1.0f, 0.0f, 0.0f);

			bool isInPoly = MathHelper.IsPointInPoly(pt, poly, poly.Length);

			Assert.IsFalse(isInPoly);
		}

		[Test]
		public void PointToSegment2DSquared_NoVectors_Success()
		{
			//point is (0, 0), segment is (0, 1) to (1,0)
{'fraction_non_alphanumeric': 0.12727041788390703, 'fraction_numerical': 0.044074685634446845, 'mean_word_length': 3.362326869806094, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1533723', 'n_tokens_mistral': 3650, 'n_tokens_neox': 3009, 'n_words': 710}