| <!DOCTYPE html> |
| <!-- |
| Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| Use of this source code is governed by a BSD-style license that can be |
| found in the LICENSE file. |
| --> |
| <link rel="import" href="/base/math.html"> |
| |
| <script> |
| 'use strict'; |
| |
| tr.b.unittest.testSuite(function() { |
| test('clamping', function() { |
| assert.equal(tr.b.clamp(2, 1, 3), 2); |
| assert.equal(tr.b.clamp(1, 1, 3), 1); |
| assert.equal(tr.b.clamp(0, 1, 3), 1); |
| assert.equal(tr.b.clamp(3, 1, 3), 3); |
| assert.equal(tr.b.clamp(4, 1, 3), 3); |
| }); |
| |
| test('interpolatePiecewiseFunction', function() { |
| var points = [[0, 0], [0.1, 0.5], [1, 1]]; |
| assert.equal(0, vec2.interpolatePiecewiseFunction(points, -1)); |
| assert.equal(0, vec2.interpolatePiecewiseFunction(points, 0)); |
| assert.equal(0.25, vec2.interpolatePiecewiseFunction(points, 0.05)); |
| assert.equal(0.5, vec2.interpolatePiecewiseFunction(points, 0.1)); |
| assert.equal(0.75, vec2.interpolatePiecewiseFunction(points, 0.55)); |
| assert.equal(1, vec2.interpolatePiecewiseFunction(points, 1)); |
| assert.equal(1, vec2.interpolatePiecewiseFunction(points, 2)); |
| }); |
| }); |
| </script> |