DeviceInfo { static int getCoresFromFileString(String str) { if (str == null || !str.matches("0-[\\d]+$")) { return DEVICEINFO_UNKNOWN; } int cores = Integer.valueOf(str.substring(2)) + 1; return cores; }  static int getNumberOfCPUCores(); static int getCPUMaxFreqKHz(); @TargetApi(Build.VERSION_CODES.JELLY_BEAN) static long getTotalMemory(Context c); static final int DEVICEINFO_UNKNOWN; }
@Test public void testFileStringValid() { assertEquals(DeviceInfo.getCoresFromFileString("0-3"), 4); assertEquals(DeviceInfo.getCoresFromFileString("0-11"), 12); }
@Test public void testFileStringInvalid() { assertEquals(DeviceInfo.getCoresFromFileString("INVALIDSTRING"), -1); assertEquals(DeviceInfo.getCoresFromFileString("0-2a"), -1); assertEquals(DeviceInfo.getCoresFromFileString("035"), -1); }