|
| 1 | +// COPYRIGHT 2022 by the Open Rails project. |
| 2 | +// |
| 3 | +// This file is part of Open Rails. |
| 4 | +// |
| 5 | +// Open Rails is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// Open Rails is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU General Public License |
| 16 | +// along with Open Rails. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | +using System.Linq; |
| 19 | +using Xunit; |
| 20 | + |
| 21 | +namespace Tests.Orts.Common |
| 22 | +{ |
| 23 | + public static class SmoothedData |
| 24 | + { |
| 25 | + [Theory] |
| 26 | + // FPS-like tests |
| 27 | + [InlineData(5, 3, 0.318)] |
| 28 | + [InlineData(10, 3, 0.337)] |
| 29 | + [InlineData(30, 3, 0.350)] |
| 30 | + [InlineData(60, 3, 0.353)] |
| 31 | + [InlineData(120, 3, 0.355)] |
| 32 | + // Physics-like tests |
| 33 | + [InlineData(60, 1, 0.000)] // Exhaust particles |
| 34 | + [InlineData(60, 2, 0.066)] // Smoke colour |
| 35 | + [InlineData(60, 45, 8.007)] // Field rate |
| 36 | + [InlineData(60, 150, 9.355)] // Burn rate |
| 37 | + [InlineData(60, 240, 9.592)] // Boiler heat |
| 38 | + public static void SmoothedFPS(int fps, float smoothPeriodS, float expected) |
| 39 | + { |
| 40 | + var period = (float)(1d / fps); |
| 41 | + var smoothed = new ORTS.Common.SmoothedData(smoothPeriodS); |
| 42 | + smoothed.Update(0, 10); |
| 43 | + foreach (var i in Enumerable.Range(0, 10 * fps)) smoothed.Update(period, 0); |
| 44 | + Assert.Equal(expected, smoothed.SmoothedValue, 3); |
| 45 | + } |
| 46 | + } |
| 47 | +} |
0 commit comments