Mercurial > gemma
comparison pkg/common/delta_test.go @ 5693:9e9cedae718a sr-v2
Add inverse funtion to delta.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 12 Feb 2024 14:38:10 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5692:d920f0fa2f04 | 5693:9e9cedae718a |
---|---|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 | |
2 // without warranty, see README.md and license for details. | |
3 // | |
4 // SPDX-License-Identifier: AGPL-3.0-or-later | |
5 // License-Filename: LICENSES/AGPL-3.0.txt | |
6 // | |
7 // Copyright (C) 2024 by via donau | |
8 // – Österreichische Wasserstraßen-Gesellschaft mbH | |
9 // Software engineering by Intevation GmbH | |
10 // | |
11 // Author(s): | |
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> | |
13 | |
14 package common | |
15 | |
16 import "testing" | |
17 | |
18 func TestDelta(t *testing.T) { | |
19 var ( | |
20 input = []int64{1, 2, 3, 2, 1} | |
21 want = []int64{1, 1, 1, -1, -1} | |
22 ) | |
23 delta := Delta() | |
24 for i, in := range input { | |
25 if got := delta(in); got != want[i] { | |
26 t.Errorf("input %d: got %d expected %d", in, got, want[i]) | |
27 } | |
28 } | |
29 } | |
30 | |
31 func TestInvDelta(t *testing.T) { | |
32 input := []int64{1, 2, 3, 2, 1, -10, 100} | |
33 delta := Delta() | |
34 invDelta := InvDelta() | |
35 for _, in := range input { | |
36 if got := invDelta(delta(in)); got != in { | |
37 t.Errorf("input %d: got %d expected %d", in, got, in) | |
38 } | |
39 } | |
40 } |