// Path: src/main/java/com/yahoo/memory4/AllocateDirectWritableMap.java
// static final void checkOffsetAndCapacity(final long offset, final long capacity) {
//   if (((offset) | (capacity - 1L) | (offset + capacity)) < 0) {
//     throw new IllegalArgumentException(
//         "offset: " + offset + ", capacity: " + capacity
//         + ", offset + capacity: " + (offset + capacity));
//   }
// }
// 
// Path: src/main/java/com/yahoo/memory4/ResourceHandler.java
// enum ResourceType { MEMORY_MAPPED_FILE, NATIVE_MEMORY }


import static com.yahoo.memory4.AllocateDirectWritableMap.checkOffsetAndCapacity;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import org.testng.annotations.Test;
import com.yahoo.memory4.ResourceHandler.ResourceType;
      Memory map = rh.get();
      rh.load();
      assertTrue(rh.isLoaded());
      //confirm orig string
      byte[] buf = new byte[(int)origBytes];
      map.getByteArray(0, buf, 0, (int)origBytes);
      String bufStr = new String(buf, UTF_8);
      assertEquals(bufStr, origStr);
    }

    try (WritableResourceHandler wrh = WritableMemory.map(origFile, 0, corrBytes)) { //longer
      WritableMemory wMap = wrh.get();
      ResourceType type = wrh.getResourceType();
      wrh.isResourceType(type);
      wrh.load();
      assertTrue(wrh.isLoaded());
      // over write content
      wMap.putByteArray(0, correctByteArr, 0, (int)corrBytes);
      wrh.force();
      //confirm correct string
      byte[] buf = new byte[(int)corrBytes];
      wMap.getByteArray(0, buf, 0, (int)corrBytes);
      String bufStr = new String(buf, UTF_8);
      assertEquals(bufStr, correctStr);
    }
  }

  @Test
  public void checkOffsetNCapacity() {
    try {
// Path: src/main/java/com/yahoo/memory4/AllocateDirectWritableMap.java
// static final void checkOffsetAndCapacity(final long offset, final long capacity) {
//   if (((offset) | (capacity - 1L) | (offset + capacity)) < 0) {
//     throw new IllegalArgumentException(
//         "offset: " + offset + ", capacity: " + capacity
//         + ", offset + capacity: " + (offset + capacity));
//   }
// }
// 
// Path: src/main/java/com/yahoo/memory4/ResourceHandler.java
// enum ResourceType { MEMORY_MAPPED_FILE, NATIVE_MEMORY }


// Path: src/test/java/com/yahoo/memory4/AllocateDirectWritableMapTest.java
import static com.yahoo.memory4.AllocateDirectWritableMap.checkOffsetAndCapacity;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import org.testng.annotations.Test;
import com.yahoo.memory4.ResourceHandler.ResourceType;

      Memory map = rh.get();
      rh.load();
      assertTrue(rh.isLoaded());
      //confirm orig string
      byte[] buf = new byte[(int)origBytes];
      map.getByteArray(0, buf, 0, (int)origBytes);
      String bufStr = new String(buf, UTF_8);
      assertEquals(bufStr, origStr);
    }

    try (WritableResourceHandler wrh = WritableMemory.map(origFile, 0, corrBytes)) { //longer
      WritableMemory wMap = wrh.get();
      ResourceType type = wrh.getResourceType();
      wrh.isResourceType(type);
      wrh.load();
      assertTrue(wrh.isLoaded());
      // over write content
      wMap.putByteArray(0, correctByteArr, 0, (int)corrBytes);
      wrh.force();
      //confirm correct string
      byte[] buf = new byte[(int)corrBytes];
      wMap.getByteArray(0, buf, 0, (int)corrBytes);
      String bufStr = new String(buf, UTF_8);
      assertEquals(bufStr, correctStr);
    }
  }

  @Test
  public void checkOffsetNCapacity() {
    try {
      checkOffsetAndCapacity(-1, 1);