You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by wl...@apache.org on 2022/10/14 14:30:00 UTC
[datasketches-memory] 02/02: Adding more tests
This is an automated email from the ASF dual-hosted git repository.
wlauer pushed a commit to branch multiReleaseRework
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git
commit f0868ceb410edce734e0598a2e61139a1a76b886
Author: Will Lauer <wl...@yahooinc.com>
AuthorDate: Fri Oct 14 09:25:10 2022 -0500
Adding more tests
---
.../datasketches/memory/WritableMemoryIT.java | 65 ++++++++++++++++++++--
1 file changed, 59 insertions(+), 6 deletions(-)
diff --git a/src/test/java/org/apache/datasketches/memory/WritableMemoryIT.java b/src/test/java/org/apache/datasketches/memory/WritableMemoryIT.java
index 92e0c89..38b6147 100644
--- a/src/test/java/org/apache/datasketches/memory/WritableMemoryIT.java
+++ b/src/test/java/org/apache/datasketches/memory/WritableMemoryIT.java
@@ -1,14 +1,31 @@
-/**
- * Copyright 2022 Yahoo Inc. All rights reserved.
+/*
+ * 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 org.apache.datasketches.memory;
import org.testng.annotations.Test;
import java.nio.ByteBuffer;
-import java.nio.CharBuffer;
+import java.nio.ByteOrder;
+import java.nio.IntBuffer;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertNotNull;
/**
@@ -29,12 +46,48 @@ public class WritableMemoryIT {
WritableMemory mem = WritableMemory.writableWrap(bb);
for (long ii = 0; ii < 26; ii++) {
- mem.putChar(ii, (char) ('a' + ii));
+ mem.putByte(ii, (byte) ('a' + ii));
+ }
+
+ for (int ii = 0; ii < 26; ++ii) {
+ assertEquals(bb.get(ii), 'a'+ii);
+ }
+ }
+
+ @Test
+ public void testWritableWrapDirect() {
+ ByteBuffer bb = ByteBuffer.allocateDirect(26);
+
+ WritableMemory mem = WritableMemory.writableWrap(bb);
+
+ for (long ii = 0; ii < 26; ii++) {
+ mem.putByte(ii, (byte) ('a' + ii));
}
- CharBuffer cb = bb.asCharBuffer();
for (int ii = 0; ii < 26; ++ii) {
- assertEquals(cb.get(ii), 'a'+ii);
+ assertEquals(bb.get(ii), 'a'+ii);
}
}
+
+ @Test
+ public void testWritableWrapEndian() {
+ ByteBuffer bb = ByteBuffer.allocateDirect(4*Integer.BYTES);
+ ByteBuffer bl = ByteBuffer.allocate(4*Integer.BYTES);
+
+ WritableMemory bigEndianMem = WritableMemory.writableWrap(bb, ByteOrder.BIG_ENDIAN);
+ WritableMemory littleEndianMem = WritableMemory.writableWrap(bl, ByteOrder.LITTLE_ENDIAN);
+
+ for (int ii = 0; ii < 4; ++ii) {
+ bigEndianMem.putInt(ii*Integer.BYTES, 0xff << (8 * ii));
+ littleEndianMem.putInt(ii*Integer.BYTES, 0xff << (8 * ii));
+ }
+
+ IntBuffer ib = bb.asIntBuffer();
+ IntBuffer il = bl.asIntBuffer();
+
+ for (int ii = 0; ii < 4; ++ii) {
+ assertNotEquals(ib.get(ii), il.get(ii));
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org