public virtual void Test() { PositionBasedTermVectorMapper mapper = new PositionBasedTermVectorMapper(); mapper.SetExpectations("test", tokens.Length, true, true); //Test single position for (int i = 0; i < tokens.Length; i++) { System.String token = tokens[i]; mapper.Map(token, 1, null, thePositions[i]); } System.Collections.IDictionary map = mapper.GetFieldToTerms(); Assert.IsTrue(map != null, "map is null and it shouldn't be"); Assert.IsTrue(map.Count == 1, "map Size: " + map.Count + " is not: " + 1); System.Collections.IDictionary positions = (System.Collections.IDictionary) map["test"]; Assert.IsTrue(positions != null, "thePositions is null and it shouldn't be"); Assert.IsTrue(positions.Count == numPositions, "thePositions Size: " + positions.Count + " is not: " + numPositions); System.Collections.BitArray bits = new System.Collections.BitArray((numPositions % 64 == 0?numPositions / 64:numPositions / 64 + 1) * 64); for (System.Collections.IEnumerator iterator = new System.Collections.Hashtable(positions).GetEnumerator(); iterator.MoveNext(); ) { System.Collections.DictionaryEntry entry = (System.Collections.DictionaryEntry) iterator.Current; PositionBasedTermVectorMapper.TVPositionInfo info = (PositionBasedTermVectorMapper.TVPositionInfo) entry.Value; Assert.IsTrue(info != null, "info is null and it shouldn't be"); int pos = ((System.Int32) entry.Key); bits.Set(pos, true); Assert.IsTrue(info.GetPosition() == pos, info.GetPosition() + " does not equal: " + pos); Assert.IsTrue(info.GetOffsets() != null, "info.getOffsets() is null and it shouldn't be"); if (pos == 0) { Assert.IsTrue(info.GetTerms().Count == 2, "info.getTerms() Size: " + info.GetTerms().Count + " is not: " + 2); //need a test for multiple terms at one pos Assert.IsTrue(info.GetOffsets().Count == 2, "info.getOffsets() Size: " + info.GetOffsets().Count + " is not: " + 2); } else { Assert.IsTrue(info.GetTerms().Count == 1, "info.getTerms() Size: " + info.GetTerms().Count + " is not: " + 1); //need a test for multiple terms at one pos Assert.IsTrue(info.GetOffsets().Count == 1, "info.getOffsets() Size: " + info.GetOffsets().Count + " is not: " + 1); } } int cardinality = 0; for (int i = 0; i < bits.Count; i++) { if (bits.Get(i)) cardinality++; } Assert.IsTrue(cardinality == numPositions, "Bits are not all on"); }
public virtual void Test() { PositionBasedTermVectorMapper mapper = new PositionBasedTermVectorMapper(); mapper.SetExpectations("test", tokens.Length, true, true); //Test single position for (int i = 0; i < tokens.Length; i++) { System.String token = tokens[i]; mapper.Map(token, 1, null, thePositions[i]); } var map = mapper.FieldToTerms; Assert.IsTrue(map != null, "map is null and it shouldn't be"); Assert.IsTrue(map.Count == 1, "map Size: " + map.Count + " is not: " + 1); var positions = map["test"]; Assert.IsNotNull(positions, "thePositions is null and it shouldn't be"); Assert.AreEqual(numPositions, positions.Count, "thePositions Size: " + positions.Count + " is not: " + numPositions); System.Collections.BitArray bits = new System.Collections.BitArray((numPositions % 64 == 0?numPositions / 64:numPositions / 64 + 1) * 64); for (var iterator = positions.GetEnumerator(); iterator.MoveNext();) { var entry = iterator.Current; PositionBasedTermVectorMapper.TVPositionInfo info = entry.Value; Assert.IsTrue(info != null, "info is null and it shouldn't be"); int pos = (int)entry.Key; bits.Set(pos, true); Assert.IsTrue(info.Position == pos, info.Position + " does not equal: " + pos); Assert.IsTrue(info.Offsets != null, "info.getOffsets() is null and it shouldn't be"); if (pos == 0) { Assert.IsTrue(info.Terms.Count == 2, "info.getTerms() Size: " + info.Terms.Count + " is not: " + 2); //need a test for multiple terms at one pos Assert.IsTrue(info.Offsets.Count == 2, "info.getOffsets() Size: " + info.Offsets.Count + " is not: " + 2); } else { Assert.IsTrue(info.Terms.Count == 1, "info.getTerms() Size: " + info.Terms.Count + " is not: " + 1); //need a test for multiple terms at one pos Assert.IsTrue(info.Offsets.Count == 1, "info.getOffsets() Size: " + info.Offsets.Count + " is not: " + 1); } } Assert.IsTrue(BitSetSupport.Cardinality(bits) == numPositions, "Bits are not all on"); }
public virtual void Test() { PositionBasedTermVectorMapper mapper = new PositionBasedTermVectorMapper(); mapper.SetExpectations("test", tokens.Length, true, true); //Test single position for (int i = 0; i < tokens.Length; i++) { System.String token = tokens[i]; mapper.Map(token, 1, null, thePositions[i]); } var map = mapper.FieldToTerms; Assert.IsTrue(map != null, "map is null and it shouldn't be"); Assert.IsTrue(map.Count == 1, "map Size: " + map.Count + " is not: " + 1); var positions = map["test"]; Assert.IsNotNull(positions, "thePositions is null and it shouldn't be"); Assert.AreEqual(numPositions, positions.Count, "thePositions Size: " + positions.Count + " is not: " + numPositions); System.Collections.BitArray bits = new System.Collections.BitArray((numPositions % 64 == 0?numPositions / 64:numPositions / 64 + 1) * 64); for (var iterator = positions.GetEnumerator(); iterator.MoveNext(); ) { var entry = iterator.Current; PositionBasedTermVectorMapper.TVPositionInfo info = entry.Value; Assert.IsTrue(info != null, "info is null and it shouldn't be"); int pos = (int)entry.Key; bits.Set(pos, true); Assert.IsTrue(info.Position == pos, info.Position + " does not equal: " + pos); Assert.IsTrue(info.Offsets != null, "info.getOffsets() is null and it shouldn't be"); if (pos == 0) { Assert.IsTrue(info.Terms.Count == 2, "info.getTerms() Size: " + info.Terms.Count + " is not: " + 2); //need a test for multiple terms at one pos Assert.IsTrue(info.Offsets.Count == 2, "info.getOffsets() Size: " + info.Offsets.Count + " is not: " + 2); } else { Assert.IsTrue(info.Terms.Count == 1, "info.getTerms() Size: " + info.Terms.Count + " is not: " + 1); //need a test for multiple terms at one pos Assert.IsTrue(info.Offsets.Count == 1, "info.getOffsets() Size: " + info.Offsets.Count + " is not: " + 1); } } Assert.IsTrue(BitSetSupport.Cardinality(bits) == numPositions, "Bits are not all on"); }