lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject svn commit: r925446 - in /lucene/lucy/trunk/core/Lucy: Object/Num.bp Object/Num.c Test/Object/TestNum.c
Date Fri, 19 Mar 2010 21:46:01 GMT
Author: marvin
Date: Fri Mar 19 21:46:01 2010
New Revision: 925446

URL: http://svn.apache.org/viewvc?rev=925446&view=rev
Log:
Implement Mimic() for all the Num classes.

Modified:
    lucene/lucy/trunk/core/Lucy/Object/Num.bp
    lucene/lucy/trunk/core/Lucy/Object/Num.c
    lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c

Modified: lucene/lucy/trunk/core/Lucy/Object/Num.bp
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/Num.bp?rev=925446&r1=925445&r2=925446&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/Num.bp (original)
+++ lucene/lucy/trunk/core/Lucy/Object/Num.bp Fri Mar 19 21:46:01 2010
@@ -76,6 +76,9 @@ class Lucy::Object::Float32 extends Lucy
 
     public incremented Float32*
     Clone(Float32 *self);
+
+    public void
+    Mimic(Float32 *self, Obj *other);
 }
 
 /** Double precision floating point number.
@@ -116,6 +119,9 @@ class Lucy::Object::Float64 extends Lucy
 
     public incremented Float64*
     Clone(Float64 *self);
+
+    public void
+    Mimic(Float64 *self, Obj *other);
 }
 
 /** 32-bit signed integer.
@@ -157,6 +163,9 @@ class Lucy::Object::Integer32 cnick Int3
 
     public incremented Integer32*
     Clone(Integer32 *self);
+
+    public void
+    Mimic(Integer32 *self, Obj *other);
 }
 
 /**
@@ -202,6 +211,9 @@ class Lucy::Object::Integer64 cnick Int6
 
     public incremented Integer64*
     Clone(Integer64 *self);
+
+    public void
+    Mimic(Integer64 *self, Obj *other);
 }
 
 /* Copyright 2009 The Apache Software Foundation

Modified: lucene/lucy/trunk/core/Lucy/Object/Num.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Object/Num.c?rev=925446&r1=925445&r2=925446&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Object/Num.c (original)
+++ lucene/lucy/trunk/core/Lucy/Object/Num.c Fri Mar 19 21:46:01 2010
@@ -128,6 +128,13 @@ Float32_clone(Float32 *self)
 }
 
 void
+Float32_mimic(Float32 *self, Obj *other)
+{
+    Float32 *evil_twin = (Float32*)CERTIFY(other, FLOAT32);
+    self->value = evil_twin->value;
+}
+
+void
 Float32_serialize(Float32 *self, OutStream *outstream)
 {
     OutStream_Write_F32(outstream, self->value);
@@ -179,6 +186,13 @@ Float64_clone(Float64 *self)
     return Float64_new(self->value);
 }
 
+void
+Float64_mimic(Float64 *self, Obj *other)
+{
+    Float64 *evil_twin = (Float64*)CERTIFY(other, FLOAT64);
+    self->value = evil_twin->value;
+}
+
 i32_t
 Float64_hash_code(Float64 *self)
 {
@@ -238,6 +252,13 @@ Int32_clone(Integer32 *self)
     return Int32_new(self->value);
 }
 
+void
+Int32_mimic(Integer32 *self, Obj *other)
+{
+    Integer32 *evil_twin = (Integer32*)CERTIFY(other, INTEGER32);
+    self->value = evil_twin->value;
+}
+
 i32_t
 Int32_hash_code(Integer32 *self)
 {
@@ -296,6 +317,13 @@ Int64_clone(Integer64 *self)
     return Int64_new(self->value);
 }
 
+void
+Int64_mimic(Integer64 *self, Obj *other)
+{
+    Integer64 *evil_twin = (Integer64*)CERTIFY(other, INTEGER64);
+    self->value = evil_twin->value;
+}
+
 i32_t
 Int64_hash_code(Integer64 *self)
 {

Modified: lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c
URL: http://svn.apache.org/viewvc/lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c?rev=925446&r1=925445&r2=925446&view=diff
==============================================================================
--- lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c (original)
+++ lucene/lucy/trunk/core/Lucy/Test/Object/TestNum.c Fri Mar 19 21:46:01 2010
@@ -169,6 +169,39 @@ test_Clone(TestBatch *batch)
 }
 
 static void
+test_Mimic(TestBatch *batch)
+{
+    Float32   *f32 = Float32_new(1.33f);
+    Float64   *f64 = Float64_new(1.33);
+    Integer32 *i32 = Int32_new(I32_MAX);
+    Integer64 *i64 = Int64_new(I64_MAX);
+    Float32   *f32_dupe = Float32_new(0.0f);
+    Float64   *f64_dupe = Float64_new(0.0);
+    Integer32 *i32_dupe = Int32_new(0);
+    Integer64 *i64_dupe = Int64_new(0);
+    Float32_Mimic(f32_dupe, (Obj*)f32);
+    Float64_Mimic(f64_dupe, (Obj*)f64);
+    Int32_Mimic(i32_dupe, (Obj*)i32);
+    Int64_Mimic(i64_dupe, (Obj*)i64);
+    ASSERT_TRUE(batch, Float32_Equals(f32, (Obj*)f32_dupe), 
+        "Float32 Mimic");
+    ASSERT_TRUE(batch, Float64_Equals(f64, (Obj*)f64_dupe),
+        "Float64 Mimic");
+    ASSERT_TRUE(batch, Int32_Equals(i32, (Obj*)i32_dupe), 
+        "Integer32 Mimic");
+    ASSERT_TRUE(batch, Int64_Equals(i64, (Obj*)i64_dupe),
+        "Integer64 Mimic");
+    DECREF(i64_dupe);
+    DECREF(i32_dupe);
+    DECREF(f64_dupe);
+    DECREF(f32_dupe);
+    DECREF(i64);
+    DECREF(i32);
+    DECREF(f64);
+    DECREF(f32);
+}
+
+static void
 test_serialization(TestBatch *batch)
 {
     Float32   *f32 = Float32_new(1.33f);
@@ -202,13 +235,14 @@ test_serialization(TestBatch *batch)
 void
 TestNum_run_tests()
 {
-    TestBatch *batch = TestBatch_new(38);
+    TestBatch *batch = TestBatch_new(42);
     TestBatch_Plan(batch);
 
     test_To_String(batch);
     test_accessors(batch);
     test_Equals_and_Compare_To(batch);
     test_Clone(batch);
+    test_Mimic(batch);
     test_serialization(batch);
     
     DECREF(batch);



Mime
View raw message