浏览代码

Add root src folder es6 unit tests

Tristan VALCKE 7 年之前
父节点
当前提交
e0187a18e9
共有 3 个文件被更改,包括 250 次插入0 次删除
  1. 139 0
      test/unit/src/constants.tests.js
  2. 74 0
      test/unit/src/polyfills.tests.js
  3. 37 0
      test/unit/src/utils.tests.js

+ 139 - 0
test/unit/src/constants.tests.js

@@ -0,0 +1,139 @@
+/**
+ * @author TristanVALCKE / https://github.com/Itee
+ */
+/* global QUnit */
+
+import * as Constants from '../../../src/constants';
+
+export default QUnit.module( 'Constants', () => {
+
+	QUnit.test( "default values", ( assert ) => {
+
+		assert.propEqual( Constants.MOUSE, { LEFT: 0, MIDDLE: 1, RIGHT: 2 }, 'MOUSE equal { LEFT: 0, MIDDLE: 1, RIGHT: 2 }' );
+		assert.equal( Constants.CullFaceNone, 0, 'CullFaceNone equal 0' );
+		assert.equal( Constants.CullFaceBack, 1, 'CullFaceBack equal 1' );
+		assert.equal( Constants.CullFaceFront, 2, 'CullFaceFront is equal to 2' );
+		assert.equal( Constants.CullFaceFrontBack, 3, 'CullFaceFrontBack is equal to 3' );
+		assert.equal( Constants.FrontFaceDirectionCW, 0, 'FrontFaceDirectionCW is equal to 0' );
+		assert.equal( Constants.FrontFaceDirectionCCW, 1, 'FrontFaceDirectionCCW is equal to 1' );
+		assert.equal( Constants.BasicShadowMap, 0, 'BasicShadowMap is equal to 0' );
+		assert.equal( Constants.PCFShadowMap, 1, 'PCFShadowMap is equal to 1' );
+		assert.equal( Constants.PCFSoftShadowMap, 2, 'PCFSoftShadowMap is equal to 2' );
+		assert.equal( Constants.FrontSide, 0, 'FrontSide is equal to 0' );
+		assert.equal( Constants.BackSide, 1, 'BackSide is equal to 1' );
+		assert.equal( Constants.DoubleSide, 2, 'DoubleSide is equal to 2' );
+		assert.equal( Constants.FlatShading, 1, 'FlatShading is equal to 1' );
+		assert.equal( Constants.SmoothShading, 2, 'SmoothShading is equal to 2' );
+		assert.equal( Constants.NoColors, 0, 'NoColors is equal to 0' );
+		assert.equal( Constants.FaceColors, 1, 'FaceColors is equal to 1' );
+		assert.equal( Constants.VertexColors, 2, 'VertexColors is equal to 2' );
+		assert.equal( Constants.NoBlending, 0, 'NoBlending is equal to 0' );
+		assert.equal( Constants.NormalBlending, 1, 'NormalBlending is equal to 1' );
+		assert.equal( Constants.AdditiveBlending, 2, 'AdditiveBlending is equal to 2' );
+		assert.equal( Constants.SubtractiveBlending, 3, 'SubtractiveBlending is equal to 3' );
+		assert.equal( Constants.MultiplyBlending, 4, 'MultiplyBlending is equal to 4' );
+		assert.equal( Constants.CustomBlending, 5, 'CustomBlending is equal to 5' );
+		assert.equal( Constants.AddEquation, 100, 'AddEquation is equal to 100' );
+		assert.equal( Constants.SubtractEquation, 101, 'SubtractEquation is equal to 101' );
+		assert.equal( Constants.ReverseSubtractEquation, 102, 'ReverseSubtractEquation is equal to 102' );
+		assert.equal( Constants.MinEquation, 103, 'MinEquation is equal to 103' );
+		assert.equal( Constants.MaxEquation, 104, 'MaxEquation is equal to 104' );
+		assert.equal( Constants.ZeroFactor, 200, 'ZeroFactor is equal to 200' );
+		assert.equal( Constants.OneFactor, 201, 'OneFactor is equal to 201' );
+		assert.equal( Constants.SrcColorFactor, 202, 'SrcColorFactor is equal to 202' );
+		assert.equal( Constants.OneMinusSrcColorFactor, 203, 'OneMinusSrcColorFactor is equal to 203' );
+		assert.equal( Constants.SrcAlphaFactor, 204, 'SrcAlphaFactor is equal to 204' );
+		assert.equal( Constants.OneMinusSrcAlphaFactor, 205, 'OneMinusSrcAlphaFactor is equal to 205' );
+		assert.equal( Constants.DstAlphaFactor, 206, 'DstAlphaFactor is equal to 206' );
+		assert.equal( Constants.OneMinusDstAlphaFactor, 207, 'OneMinusDstAlphaFactor is equal to 207' );
+		assert.equal( Constants.DstColorFactor, 208, 'DstColorFactor is equal to 208' );
+		assert.equal( Constants.OneMinusDstColorFactor, 209, 'OneMinusDstColorFactor is equal to 209' );
+		assert.equal( Constants.SrcAlphaSaturateFactor, 210, 'SrcAlphaSaturateFactor is equal to 210' );
+		assert.equal( Constants.NeverDepth, 0, 'NeverDepth is equal to 0' );
+		assert.equal( Constants.AlwaysDepth, 1, 'AlwaysDepth is equal to 1' );
+		assert.equal( Constants.LessDepth, 2, 'LessDepth is equal to 2' );
+		assert.equal( Constants.LessEqualDepth, 3, 'LessEqualDepth is equal to 3' );
+		assert.equal( Constants.EqualDepth, 4, 'EqualDepth is equal to 4' );
+		assert.equal( Constants.GreaterEqualDepth, 5, 'GreaterEqualDepth is equal to 5' );
+		assert.equal( Constants.GreaterDepth, 6, 'GreaterDepth is equal to 6' );
+		assert.equal( Constants.NotEqualDepth, 7, 'NotEqualDepth is equal to 7' );
+		assert.equal( Constants.MultiplyOperation, 0, 'MultiplyOperation is equal to 0' );
+		assert.equal( Constants.MixOperation, 1, 'MixOperation is equal to 1' );
+		assert.equal( Constants.AddOperation, 2, 'AddOperation is equal to 2' );
+		assert.equal( Constants.NoToneMapping, 0, 'NoToneMapping is equal to 0' );
+		assert.equal( Constants.LinearToneMapping, 1, 'LinearToneMapping is equal to 1' );
+		assert.equal( Constants.ReinhardToneMapping, 2, 'ReinhardToneMapping is equal to 2' );
+		assert.equal( Constants.Uncharted2ToneMapping, 3, 'Uncharted2ToneMapping is equal to 3' );
+		assert.equal( Constants.CineonToneMapping, 4, 'CineonToneMapping is equal to 4' );
+		assert.equal( Constants.UVMapping, 300, 'UVMapping is equal to 300' );
+		assert.equal( Constants.CubeReflectionMapping, 301, 'CubeReflectionMapping is equal to 301' );
+		assert.equal( Constants.CubeRefractionMapping, 302, 'CubeRefractionMapping is equal to 302' );
+		assert.equal( Constants.EquirectangularReflectionMapping, 303, 'EquirectangularReflectionMapping is equal to 303' );
+		assert.equal( Constants.EquirectangularRefractionMapping, 304, 'EquirectangularRefractionMapping is equal to 304' );
+		assert.equal( Constants.SphericalReflectionMapping, 305, 'SphericalReflectionMapping is equal to 305' );
+		assert.equal( Constants.CubeUVReflectionMapping, 306, 'CubeUVReflectionMapping is equal to 306' );
+		assert.equal( Constants.CubeUVRefractionMapping, 307, 'CubeUVRefractionMapping is equal to 307' );
+		assert.equal( Constants.RepeatWrapping, 1000, 'RepeatWrapping is equal to 1000' );
+		assert.equal( Constants.ClampToEdgeWrapping, 1001, 'ClampToEdgeWrapping is equal to 1001' );
+		assert.equal( Constants.MirroredRepeatWrapping, 1002, 'MirroredRepeatWrapping is equal to 1002' );
+		assert.equal( Constants.NearestFilter, 1003, 'NearestFilter is equal to 1003' );
+		assert.equal( Constants.NearestMipMapNearestFilter, 1004, 'NearestMipMapNearestFilter is equal to 1004' );
+		assert.equal( Constants.NearestMipMapLinearFilter, 1005, 'NearestMipMapLinearFilter is equal to 1005' );
+		assert.equal( Constants.LinearFilter, 1006, 'LinearFilter is equal to 1006' );
+		assert.equal( Constants.LinearMipMapNearestFilter, 1007, 'LinearMipMapNearestFilter is equal to 1007' );
+		assert.equal( Constants.LinearMipMapLinearFilter, 1008, 'LinearMipMapLinearFilter is equal to 1008' );
+		assert.equal( Constants.UnsignedByteType, 1009, 'UnsignedByteType is equal to 1009' );
+		assert.equal( Constants.ByteType, 1010, 'ByteType is equal to 1010' );
+		assert.equal( Constants.ShortType, 1011, 'ShortType is equal to 1011' );
+		assert.equal( Constants.UnsignedShortType, 1012, 'UnsignedShortType is equal to 1012' );
+		assert.equal( Constants.IntType, 1013, 'IntType is equal to 1013' );
+		assert.equal( Constants.UnsignedIntType, 1014, 'UnsignedIntType is equal to 1014' );
+		assert.equal( Constants.FloatType, 1015, 'FloatType is equal to 1015' );
+		assert.equal( Constants.HalfFloatType, 1016, 'HalfFloatType is equal to 1016' );
+		assert.equal( Constants.UnsignedShort4444Type, 1017, 'UnsignedShort4444Type is equal to 1017' );
+		assert.equal( Constants.UnsignedShort5551Type, 1018, 'UnsignedShort5551Type is equal to 1018' );
+		assert.equal( Constants.UnsignedShort565Type, 1019, 'UnsignedShort565Type is equal to 1019' );
+		assert.equal( Constants.UnsignedInt248Type, 1020, 'UnsignedInt248Type is equal to 1020' );
+		assert.equal( Constants.AlphaFormat, 1021, 'AlphaFormat is equal to 1021' );
+		assert.equal( Constants.RGBFormat, 1022, 'RGBFormat is equal to 1022' );
+		assert.equal( Constants.RGBAFormat, 1023, 'RGBAFormat is equal to 1023' );
+		assert.equal( Constants.LuminanceFormat, 1024, 'LuminanceFormat is equal to 1024' );
+		assert.equal( Constants.LuminanceAlphaFormat, 1025, 'LuminanceAlphaFormat is equal to 1025' );
+		assert.equal( Constants.RGBEFormat, Constants.RGBAFormat, 'RGBEFormat is equal to RGBAFormat' );
+		assert.equal( Constants.DepthFormat, 1026, 'DepthFormat is equal to 1026' );
+		assert.equal( Constants.DepthStencilFormat, 1027, 'DepthStencilFormat is equal to 1027' );
+		assert.equal( Constants.RGB_S3TC_DXT1_Format, 2001, 'RGB_S3TC_DXT1_Format is equal to 2001' );
+		assert.equal( Constants.RGBA_S3TC_DXT1_Format, 2002, 'RGBA_S3TC_DXT1_Format is equal to 2002' );
+		assert.equal( Constants.RGBA_S3TC_DXT3_Format, 2003, 'RGBA_S3TC_DXT3_Format is equal to 2003' );
+		assert.equal( Constants.RGBA_S3TC_DXT5_Format, 2004, 'RGBA_S3TC_DXT5_Format is equal to 2004' );
+		assert.equal( Constants.RGB_PVRTC_4BPPV1_Format, 2100, 'RGB_PVRTC_4BPPV1_Format is equal to 2100' );
+		assert.equal( Constants.RGB_PVRTC_2BPPV1_Format, 2101, 'RGB_PVRTC_2BPPV1_Format is equal to 2101' );
+		assert.equal( Constants.RGBA_PVRTC_4BPPV1_Format, 2102, 'RGBA_PVRTC_4BPPV1_Format is equal to 2102' );
+		assert.equal( Constants.RGBA_PVRTC_2BPPV1_Format, 2103, 'RGBA_PVRTC_2BPPV1_Format is equal to 2103' );
+		assert.equal( Constants.RGB_ETC1_Format, 2151, 'RGB_ETC1_Format is equal to 2151' );
+		assert.equal( Constants.LoopOnce, 2200, 'LoopOnce is equal to 2200' );
+		assert.equal( Constants.LoopRepeat, 2201, 'LoopRepeat is equal to 2201' );
+		assert.equal( Constants.LoopPingPong, 2202, 'LoopPingPong is equal to 2202' );
+		assert.equal( Constants.InterpolateDiscrete, 2300, 'InterpolateDiscrete is equal to 2300' );
+		assert.equal( Constants.InterpolateLinear, 2301, 'InterpolateLinear is equal to 2301' );
+		assert.equal( Constants.InterpolateSmooth, 2302, 'InterpolateSmooth is equal to 2302' );
+		assert.equal( Constants.ZeroCurvatureEnding, 2400, 'ZeroCurvatureEnding is equal to 2400' );
+		assert.equal( Constants.ZeroSlopeEnding, 2401, 'ZeroSlopeEnding is equal to 2401' );
+		assert.equal( Constants.WrapAroundEnding, 2402, 'WrapAroundEnding is equal to 2402' );
+		assert.equal( Constants.TrianglesDrawMode, 0, 'TrianglesDrawMode is equal to 0' );
+		assert.equal( Constants.TriangleStripDrawMode, 1, 'TriangleStripDrawMode is equal to 1' );
+		assert.equal( Constants.TriangleFanDrawMode, 2, 'TriangleFanDrawMode is equal to 2' );
+		assert.equal( Constants.LinearEncoding, 3000, 'LinearEncoding is equal to 3000' );
+		assert.equal( Constants.sRGBEncoding, 3001, 'sRGBEncoding is equal to 3001' );
+		assert.equal( Constants.GammaEncoding, 3007, 'GammaEncoding is equal to 3007' );
+		assert.equal( Constants.RGBEEncoding, 3002, 'RGBEEncoding is equal to 3002' );
+		assert.equal( Constants.LogLuvEncoding, 3003, 'LogLuvEncoding is equal to 3003' );
+		assert.equal( Constants.RGBM7Encoding, 3004, 'RGBM7Encoding is equal to 3004' );
+		assert.equal( Constants.RGBM16Encoding, 3005, 'RGBM16Encoding is equal to 3005' );
+		assert.equal( Constants.RGBDEncoding, 3006, 'RGBDEncoding is equal to 3006' );
+		assert.equal( Constants.BasicDepthPacking, 3200, 'BasicDepthPacking is equal to 3200' );
+		assert.equal( Constants.RGBADepthPacking, 3201, 'RGBADepthPacking is equal to 3201' );
+
+	} );
+
+} );

+ 74 - 0
test/unit/src/polyfills.tests.js

@@ -0,0 +1,74 @@
+/**
+ * @author TristanVALCKE / https://github.com/Itee
+ */
+/* global QUnit */
+
+import '../../../src/polyfills';
+import { Vector3 } from '../../../src/math/Vector3';
+
+export default QUnit.module.todo( 'Polyfills', () => {
+
+	// PUBLIC STUFF
+	QUnit.test( "Number.EPSILON", ( assert ) => {
+
+		assert.ok( false, "everything's gonna be alright" );
+
+	} );
+
+	QUnit.test( "Number.isInteger", ( assert ) => {
+
+		assert.ok( false, "everything's gonna be alright" );
+
+	} );
+
+	//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
+	//http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.sign
+	/*
+	 20.2.2.29 Math.sign(x)
+
+	 Returns the sign of the x, indicating whether x is positive, negative or zero.
+
+	 If x is NaN, the result is NaN.
+	 If x is -0, the result is -0.
+	 If x is +0, the result is +0.
+	 If x is negative and not -0, the result is -1.
+	 If x is positive and not +0, the result is +1.
+	 */
+	QUnit.test( "Math.sign", ( assert ) => {
+
+		assert.ok( isNaN( Math.sign( NaN ) ), "If x is NaN<NaN>, the result is NaN." );
+		assert.ok( isNaN( Math.sign( new Vector3() ) ), "If x is NaN<object>, the result is NaN." );
+		assert.ok( isNaN( Math.sign() ), "If x is NaN<undefined>, the result is NaN." );
+		assert.ok( isNaN( Math.sign( '--3' ) ), "If x is NaN<'--3'>, the result is NaN." );
+		assert.ok( isNegativeZero( Math.sign( - 0 ) ), "If x is -0, the result is -0." );
+		assert.ok( Math.sign( + 0 ) === + 0, "If x is +0, the result is +0." );
+		assert.ok( Math.sign( - Infinity ) === - 1, "If x is negative<-Infinity> and not -0, the result is -1." );
+		assert.ok( Math.sign( '-3' ) === - 1, "If x is negative<'-3'> and not -0, the result is -1." );
+		assert.ok( Math.sign( '-1e-10' ) === - 1, "If x is negative<'-1e-10'> and not -0, the result is -1." );
+		assert.ok( Math.sign( + Infinity ) === + 1, "If x is positive<+Infinity> and not +0, the result is +1." );
+		assert.ok( Math.sign( '+3' ) === + 1, "If x is positive<'+3'> and not +0, the result is +1." );
+
+		// Comparing with -0 is tricky because 0 === -0. But
+		// luckily 1 / -0 === -Infinity so we can use that.
+
+		function isNegativeZero( value ) {
+
+			return value === 0 && 1 / value < 0;
+
+		}
+
+	} );
+
+	QUnit.test( "'name' in Function.prototype", ( assert ) => {
+
+		assert.ok( false, "everything's gonna be alright" );
+
+	} );
+
+	QUnit.test( "Object.assign", ( assert ) => {
+
+		assert.ok( false, "everything's gonna be alright" );
+
+	} );
+
+} );

+ 37 - 0
test/unit/src/utils.tests.js

@@ -0,0 +1,37 @@
+/**
+ * @author alemures / https://github.com/alemures
+ * @author TristanVALCKE / https://github.com/Itee
+ */
+/* global QUnit */
+
+import { arrayMin, arrayMax } from '../../../src/utils';
+
+QUnit.module( 'utils', () => {
+
+	QUnit.test( 'arrayMin', ( assert ) => {
+
+		assert.equal( arrayMin( [] ), Infinity, 'Empty array return positive infinit' );
+		assert.equal( arrayMin( [ 5 ] ), 5, 'Single valued array should return the unique value as minimum' );
+		assert.equal( arrayMin( [ 1, 5, 10 ] ), 1, 'The array [ 1, 5, 10 ] return 1' );
+		assert.equal( arrayMin( [ 5, 1, 10 ] ), 1, 'The array [ 5, 1, 10 ] return 1' );
+		assert.equal( arrayMin( [ 10, 5, 1 ] ), 1, 'The array [ 10, 5, 1 ] return 1' );
+		assert.equal( arrayMax( [ - 0, 0 ] ), - 0, 'The array [ - 0, 0 ] return -0' );
+		assert.equal( arrayMin( [ - Infinity, 0, Infinity ] ), - Infinity, 'The array [ - Infinity, 0, Infinity ] return -Infinity' );
+
+	} );
+
+	QUnit.test( 'arrayMax', ( assert ) => {
+
+		assert.equal( arrayMax( [] ), - Infinity, 'Empty array return negative infinit' );
+		assert.equal( arrayMax( [ 5 ] ), 5, 'Single valued array should return the unique value as maximum' );
+		assert.equal( arrayMax( [ 10, 5, 1 ] ), 10, 'The array [ 10, 5, 1 ] return 10' );
+		assert.equal( arrayMax( [ 1, 10, 5 ] ), 10, 'The array [ 1, 10, 5 ] return 10' );
+		assert.equal( arrayMax( [ 1, 5, 10 ] ), 10, 'The array [ 1, 5, 10 ] return 10' );
+		assert.equal( arrayMax( [ - 0, 0 ] ), 0, 'The array [ - 0, 0 ] return 0' );
+		assert.equal( arrayMax( [ - Infinity, 0, Infinity ] ), Infinity, 'The array [ - Infinity, 0, Infinity ] return Infinity' );
+
+	} );
+
+
+} );
+