From b290454115975c09db0efc535f99e0753a321141 Mon Sep 17 00:00:00 2001 From: Tom Fili Date: Thu, 27 Jun 2019 10:53:36 -0400 Subject: [PATCH 1/3] Fixed factorial to actually work. It would only work if you called it in a loop in order, so I changed the test to not do that --- Source/Core/Math.js | 4 +++- Specs/Core/MathSpec.js | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Source/Core/Math.js b/Source/Core/Math.js index 4fea256d881f..488d127b466e 100644 --- a/Source/Core/Math.js +++ b/Source/Core/Math.js @@ -732,7 +732,9 @@ define([ if (n >= length) { var sum = factorials[length - 1]; for (var i = length; i <= n; i++) { - factorials.push(sum * i); + var next = sum * i; + factorials.push(next); + sum = next; } } return factorials[n]; diff --git a/Specs/Core/MathSpec.js b/Specs/Core/MathSpec.js index 164daa2717e0..2b6b47f4049d 100644 --- a/Specs/Core/MathSpec.js +++ b/Specs/Core/MathSpec.js @@ -383,8 +383,26 @@ defineSuite([ var factorials = [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 6227020800, 87178291200, 1307674368000, 20922789888000, 355687428096000, 6402373705728000, 121645100408832000, 2432902008176640000, 51090942171709440000, 1124000727777607680000, 25852016738884976640000, 620448401733239439360000]; - for ( var i = 0; i < factorials.length; i++) { - expect(CesiumMath.factorial(i)).toEqual(factorials[i]); + var length = factorials.length; + var i; + var indices = []; + + // Populate indices array + for (i = 0; i < length; i++) { + indices.push(i); + } + + // Randomize the indices array + for (i = 0; i < length; i++) { + var tmp = indices[i]; + var randomIndex = Math.floor(Math.random() * length); + indices[i] = indices[randomIndex]; + indices[randomIndex] = tmp; + } + + for (i = 0; i < length; i++) { + var index = indices[i]; + expect(CesiumMath.factorial(index)).toEqual(factorials[index]); } }); From 81eec9d5ab93fbf2505ca001174a61a97fd9c31f Mon Sep 17 00:00:00 2001 From: Tom Fili Date: Thu, 27 Jun 2019 11:16:52 -0400 Subject: [PATCH 2/3] Update CHANGES.md --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index 8d47edf363df..6c384d5c92da 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ Change Log * Fixed a bug where image requests that returned HTTP code 204 would prevent any future request from succeeding on browsers that supported ImageBitmap. [#7914](https://github.com/AnalyticalGraphicsInc/cesium/pull/7914/) * Fixed polyline colors when `scene.highDynamicRange` is enabled. [#7924](https://github.com/AnalyticalGraphicsInc/cesium/pull/7924) * Fixed a bug in the inspector where the min/max height values of a picked tile were undefined. [#7904](https://github.com/AnalyticalGraphicsInc/cesium/pull/7904) +* Fixed Math.factorial to return the correct values. (https://github.com/AnalyticalGraphicsInc/cesium/pull/7969) ### 1.58.1 - 2018-06-03 _This is an npm-only release to fix a publishing issue_. From 2ea44421fb4ab7f5f1fbb2fb9cd57177d14a7226 Mon Sep 17 00:00:00 2001 From: Tom Fili Date: Thu, 27 Jun 2019 11:17:16 -0400 Subject: [PATCH 3/3] Update CHANGES.md --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 6c384d5c92da..0243f1619607 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,7 +15,7 @@ Change Log * Fixed a bug where image requests that returned HTTP code 204 would prevent any future request from succeeding on browsers that supported ImageBitmap. [#7914](https://github.com/AnalyticalGraphicsInc/cesium/pull/7914/) * Fixed polyline colors when `scene.highDynamicRange` is enabled. [#7924](https://github.com/AnalyticalGraphicsInc/cesium/pull/7924) * Fixed a bug in the inspector where the min/max height values of a picked tile were undefined. [#7904](https://github.com/AnalyticalGraphicsInc/cesium/pull/7904) -* Fixed Math.factorial to return the correct values. (https://github.com/AnalyticalGraphicsInc/cesium/pull/7969) +* Fixed `Math.factorial` to return the correct values. (https://github.com/AnalyticalGraphicsInc/cesium/pull/7969) ### 1.58.1 - 2018-06-03 _This is an npm-only release to fix a publishing issue_.