Test Go bindings for Similarity.

Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/656f6932
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/656f6932
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/656f6932

Branch: refs/heads/master
Commit: 656f6932893ef72672a09292dd94ae04339f6ba7
Parents: c8df9f6
Author: Marvin Humphrey <[email protected]>
Authored: Sat Oct 31 21:01:51 2015 -0700
Committer: Marvin Humphrey <[email protected]>
Committed: Sun Nov 1 10:00:35 2015 -0800

----------------------------------------------------------------------
 go/lucy/index_test.go | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/656f6932/go/lucy/index_test.go
----------------------------------------------------------------------
diff --git a/go/lucy/index_test.go b/go/lucy/index_test.go
index d60e59b..47cb461 100644
--- a/go/lucy/index_test.go
+++ b/go/lucy/index_test.go
@@ -429,6 +429,48 @@ func TestSortCacheMisc(t *testing.T) {
        }
 }
 
+func TestSimilarityMisc(t *testing.T) {
+       sim := NewSimilarity()
+       if _, ok := sim.MakePosting().(Posting); !ok {
+               t.Errorf("MakePosting")
+       }
+       if got := sim.TF(4.0); got != 2.0 {
+               t.Errorf("TF: %f", got)
+       }
+       if got := sim.IDF(40, 1000); got <= 0 {
+               t.Errorf("IDF: %f", got)
+       }
+       if got := sim.Coord(3, 4); got <= 0 {
+               t.Errorf("Coord: %f", got)
+       }
+       if got := sim.LengthNorm(4); got != 0.5 {
+               t.Errorf("LengthNorm: %f", got)
+       }
+       if got := sim.QueryNorm(4); got != 0.5 {
+               t.Errorf("QueryNorm: %f", got)
+       }
+       if got := sim.EncodeNorm(sim.DecodeNorm(42)); got != 42 {
+               t.Errorf("Encode/DecodeNorm: %d", got)
+       }
+}
+
+func TestSimilarityRoundTrip(t *testing.T) {
+       sim := NewSimilarity()
+       dupe := sim.Load(sim.Dump())
+       if !sim.Equals(dupe) {
+               t.Errorf("Dump/Load round-trip")
+       }
+       folder := NewRAMFolder("")
+       out, _ := folder.OpenOut("dump")
+       sim.Serialize(out)
+       out.Close()
+       in, _ := folder.OpenIn("dump")
+       dupe = clownfish.GetClass(sim).MakeObj().(Similarity).Deserialize(in)
+       if !sim.Equals(dupe) {
+               t.Errorf("Serialize/Deserialize round-trip")
+       }
+}
+
 func TestSegmentMisc(t *testing.T) {
        var err error
 

Reply via email to