public void Test_KC_FloatVector_Normalize() { float[] floats = { 0.1F, 0.2F, 0.3F, 0.4F, 0.5F }; KC_FloatVector fv = new KC_FloatVector(floats); Assert.False(fv.IsNormalized); Assert.Null(fv.NormalizedVector); fv.Normalize(); Assert.Equal(floats, fv.FloatVector); float[] normfloats = { 0.13483997249264842F, 0.26967994498529685F, 0.40451991747794525F, 0.5393598899705937F, 0.674199862463242F }; for (int i = 0; i < floats.Length; i++) { Assert.True(EqualWithinTolerance(normfloats[i], fv.NormalizedVector[i])); } float[] normalized = new float [fv.NormalizedVector.Count]; fv.NormalizedVector.CopyTo(normalized, 0); double normlen = KC_FloatVector.Length(normalized); Assert.True(EqualWithinTolerance(1.0, normlen)); Assert.True(fv.IsNormalized); fv.FloatVector = new float[] { 9.0F, 8.0F, 7.0F }; Assert.False(fv.IsNormalized); Assert.Null(fv.NormalizedVector); }
public void Test_KC_FloatVector_Length() { float[] floats = { 1.0F, 2.0F, 3.0F, 4.0F, 5.0F }; double len = KC_FloatVector.Length(floats); Assert.True(EqualWithinTolerance(len, 7.416198)); KC_FloatVector fv = new KC_FloatVector(floats); Assert.True(EqualWithinTolerance(fv.Length(), 7.416198)); }