1/*
2
3 This Source Code Form is subject to the terms of the Mozilla Public
4 License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 You can obtain one at http://mozilla.org/MPL/2.0/.
6
7 Copyright (c) 2013, Armon Dadgar armon.dadgar@gmail.com
8 Copyright (c) 2013, Mitchell Hashimoto mitchell.hashimoto@gmail.com
9
10 Alternatively, the contents of this file may be used under the terms
11 of the GNU General Public License Version 3 or later, as described below:
12
13 This file is free software: you may copy, redistribute and/or modify
14 it under the terms of the GNU General Public License as published by the
15 Free Software Foundation, either version 3 of the License, or (at your
16 option) any later version.
17
18 This file is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
21 Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see http://www.gnu.org/licenses/.
25
26*/
27
28package util
29
30import (
31 "testing"
32)
33
34func TestLamportClock(t *testing.T) {
35 l := &LamportClock{}
36
37 if l.Time() != 0 {
38 t.Fatalf("bad time value")
39 }
40
41 if l.Increment() != 1 {
42 t.Fatalf("bad time value")
43 }
44
45 if l.Time() != 1 {
46 t.Fatalf("bad time value")
47 }
48
49 l.Witness(41)
50
51 if l.Time() != 42 {
52 t.Fatalf("bad time value")
53 }
54
55 l.Witness(41)
56
57 if l.Time() != 42 {
58 t.Fatalf("bad time value")
59 }
60
61 l.Witness(30)
62
63 if l.Time() != 42 {
64 t.Fatalf("bad time value")
65 }
66}