Tests for Integer Go bindings.
Project: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/repo Commit: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/commit/6a43f1e5 Tree: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/tree/6a43f1e5 Diff: http://git-wip-us.apache.org/repos/asf/lucy-clownfish/diff/6a43f1e5 Branch: refs/heads/master Commit: 6a43f1e570f9bb4abe3cae712c2351df1eec0fea Parents: 82023cc Author: Marvin Humphrey <[email protected]> Authored: Wed Aug 5 19:10:00 2015 -0700 Committer: Marvin Humphrey <[email protected]> Committed: Thu Aug 6 19:51:33 2015 -0700 ---------------------------------------------------------------------- runtime/go/clownfish/integer_test.go | 106 ++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucy-clownfish/blob/6a43f1e5/runtime/go/clownfish/integer_test.go ---------------------------------------------------------------------- diff --git a/runtime/go/clownfish/integer_test.go b/runtime/go/clownfish/integer_test.go new file mode 100644 index 0000000..2d12fb4 --- /dev/null +++ b/runtime/go/clownfish/integer_test.go @@ -0,0 +1,106 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package clownfish + +import "testing" + +func TestIntGetValue(t *testing.T) { + fortyTwo := NewInteger(42) + if got := fortyTwo.GetValue(); got != 42 { + t.Errorf("Expected 42, got %d", got) + } +} + +func TestIntToF64(t *testing.T) { + fortyTwo := NewInteger(42) + if got := fortyTwo.ToF64(); got != 42.0 { + t.Errorf("Expected 42.0, got %f", got) + } +} + +func TestIntToBool(t *testing.T) { + fortyTwo := NewInteger(42) + if got := fortyTwo.ToBool(); !got { + t.Errorf("Expected true, got %v", got) + } + zero := NewInteger(0) + if got := zero.ToBool(); got { + t.Errorf("Expected false, got %v", got) + } +} + +func TestIntToString(t *testing.T) { + fortyTwo := NewInteger(42) + if got := fortyTwo.ToString(); got != "42" { + t.Errorf("Expected \"42\", got %s", got) + } +} + +func TestIntClone(t *testing.T) { + fortyTwo := NewInteger(42) + dupe := fortyTwo.Clone().(Integer) + if got := dupe.GetValue(); got != 42 { + t.Errorf("Expected 42, got %d", got) + } +} + +func TestIntCompareTo(t *testing.T) { + fortyTwo := NewInteger(42) + if got := fortyTwo.CompareTo(43); got >= 0 { + t.Errorf("42 CompareTo 43: %v", got) + } + if got := fortyTwo.CompareTo(42); got != 0 { + t.Errorf("42 CompareTo 42: %v", got) + } + if got := fortyTwo.CompareTo(42.1); got >= 0 { + t.Errorf("42 CompareTo 42.1: %v", got) + } + if got := fortyTwo.CompareTo(41.9); got <= 0 { + t.Errorf("42 CompareTo 41.9: %v", got) + } +} + +func TestIntEquals(t *testing.T) { + fortyTwo := NewInteger(42) + fortyThree := NewInteger(43) + fortyTwoPointZero := NewFloat(42.0) + dupe := fortyTwo.Clone().(Integer) + if !fortyTwo.Equals(dupe) { + t.Error("Equal Clownfish Integer") + } + if !fortyTwo.Equals(42) { + t.Error("Equal Go integer") + } + if !fortyTwo.Equals(42.0) { + t.Error("Equal Go float64") + } + if !fortyTwo.Equals(fortyTwoPointZero) { + t.Error("Equal Clownfish Float") + } + if fortyTwo.Equals(fortyThree) { + t.Error("Non-equal Clownfish Integer") + } + if fortyTwo.Equals(43) { + t.Error("Non-equal Go integer") + } + if fortyTwo.Equals(42.1) { + t.Error("Non-equal Go float64") + } + if fortyTwo.Equals("foo") { + t.Error("Non-equal Go string") + } +}
