示例#1
45
  @Test
  public void testProtocolBestMoveCommand() throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    UciProtocol protocol =
        new UciProtocol(
            new BufferedReader(new InputStreamReader(new ByteArrayInputStream("".getBytes()))),
            new PrintStream(buffer));

    // 1. Test
    ProtocolBestMoveCommand command =
        new ProtocolBestMoveCommand(
            new GenericMove(GenericPosition.a2, GenericPosition.a3),
            new GenericMove(GenericPosition.d3, GenericPosition.e5));
    protocol.send(command);

    // 2. Test
    command = new ProtocolBestMoveCommand(null, null);
    protocol.send(command);

    BufferedReader input =
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray())));

    // 1. Test
    String line = input.readLine();
    assertEquals("bestmove a2a3 ponder d3e5", line);

    // 2. Test
    line = input.readLine();
    assertEquals("bestmove nomove", line);

    assertNull(input.readLine());
  }
示例#2
0
  @Test
  public void testProtocolInformationCommand() throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    UciProtocol protocol =
        new UciProtocol(
            new BufferedReader(new InputStreamReader(new ByteArrayInputStream("".getBytes()))),
            new PrintStream(buffer));

    ProtocolInformationCommand command = new ProtocolInformationCommand();
    command.setDepth(8);
    command.setMaxDepth(20);
    command.setCentipawns(400);
    command.setCurrentMove(new GenericMove(GenericPosition.a2, GenericPosition.a3));
    command.setCurrentMoveNumber(30);
    command.setHash(50);
    command.setNps(300);
    command.setTime(3000);
    command.setNodes(5000);
    protocol.send(command);

    BufferedReader input =
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray())));
    String line = input.readLine();
    assertEquals(
        "info depth 8 seldepth 20 score cp 400 currmove a2a3 currmovenumber 30 hashfull 50 nps 300 time 3000 nodes 5000",
        line);
    assertNull(input.readLine());
  }
示例#3
0
  // @Test
  public void validateDoubfulRanks() {

    try {
      BufferedReader bufferedReader =
          new BufferedReader(
              new FileReader(new File("/home/alext/Downloads/NCBI/taxdump/nodes.dmp")));
      String line;
      while ((line = bufferedReader.readLine()) != null) {
        String[] split = line.split("\t\\|\t");
        if (split[2].equals("forma")) {
          System.out.println(line);
          // break;
        }
      }
      bufferedReader.close();
    } catch (FileNotFoundException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } catch (IOException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    }
  }
 protected void doService(Socket s) throws IOException {
   InputStream is = s.getInputStream();
   InputStreamReader isr = new InputStreamReader(is);
   BufferedReader br = new BufferedReader(isr);
   String message = br.readLine();
   OutputStream os = s.getOutputStream();
   os.write(message.getBytes());
   os.flush();
 }
 private static boolean isAaptPresent() throws Exception {
   boolean result = true;
   try {
     Process proc = Runtime.getRuntime().exec("aapt");
     BufferedReader br = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
     String line = null;
     while ((line = br.readLine()) != null) {}
   } catch (Exception ex) {
     result = false;
   }
   return result;
 }
示例#6
0
  @Test
  public void testProtocolReadyAnswerCommand() throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    UciProtocol protocol =
        new UciProtocol(
            new BufferedReader(new InputStreamReader(new ByteArrayInputStream("".getBytes()))),
            new PrintStream(buffer));

    ProtocolReadyAnswerCommand command = new ProtocolReadyAnswerCommand("does not matter");
    protocol.send(command);

    BufferedReader input =
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray())));
    String line = input.readLine();
    assertEquals("readyok", line);
    assertNull(input.readLine());
  }
示例#7
0
 public List<String> linesThat(Matcher<? super String> matcher) {
   try {
     BufferedReader reader = new BufferedReader(new FileReader(this));
     try {
       List<String> lines = new ArrayList<String>();
       String line;
       while ((line = reader.readLine()) != null) {
         if (matcher.matches(line)) {
           lines.add(line);
         }
       }
       return lines;
     } finally {
       reader.close();
     }
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
示例#8
0
  @Test
  public void testMachine() throws Exception {
    if (!isUnix()) return;

    Process p = Runtime.getRuntime().exec(new String[] {"uname", "-m"});
    BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));

    String uname = r.readLine().trim();
    String m = uname;
    assertTrue(m.length() > 0);

    if (m.matches("i\\d86")) m = "i386";
    else if (m.matches("i86pc")) m = "x86";

    if (m.equals("i386") && Platform.is64Bits()) m = "x86_64";

    assertEquals(
        "uname = " + uname + ", Platform.getMachine = " + Platform.getMachine(),
        m,
        Platform.getMachine());
  }
示例#9
0
  /*	@Test
  public void searchContentTest() throws IOException {
  	System.out.println("Search");
  	textbuddy.searchContent("textfile.txt");

  }*/
  public boolean testIfFilesAreTheSame(File file1, File file2) {
    BufferedReader file1Reader = null;
    BufferedReader file2Reader = null;
    boolean equals = true;
    ;
    try {
      file1Reader = new BufferedReader(new FileReader(file1));
      file2Reader = new BufferedReader(new FileReader(file2));
      String linefromfile1;
      String linefromfile2;
      while (((linefromfile1 = file1Reader.readLine()) != null)
          && ((linefromfile2 = file2Reader.readLine()) != null)) {
        if (!linefromfile1.equals(linefromfile2)) {
          equals = false;
          break;
        }
      }

    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        file1Reader.close();
        file2Reader.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return equals;
  }
示例#10
0
  @Test
  public void testProtocolInitializeAnswerCommand() throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    UciProtocol protocol =
        new UciProtocol(
            new BufferedReader(new InputStreamReader(new ByteArrayInputStream("".getBytes()))),
            new PrintStream(buffer));

    ProtocolInitializeAnswerCommand command =
        new ProtocolInitializeAnswerCommand("My Engine", "The Author");
    command.addOption(new Option("Hash", "spin", "16", "4", "64", null));
    protocol.send(command);

    BufferedReader input =
        new BufferedReader(new InputStreamReader(new ByteArrayInputStream(buffer.toByteArray())));
    String line = input.readLine();
    assertEquals("id name My Engine", line);
    line = input.readLine();
    assertEquals("id author The Author", line);
    line = input.readLine();
    assertEquals("option name Hash type spin default 16 min 4 max 64", line);
    line = input.readLine();
    assertEquals("uciok", line);
    assertNull(input.readLine());
  }
示例#11
0
  @Test
  public void testSave() {
    List<String> values = new ArrayList<String>();
    values.add("one");
    values.add("two");
    values.add("three");

    String[] mutex = new String[] {"testArg", "testArg2"};

    p.setProgramName("Test");
    p.setProgramDescription("Test Program");
    p.addArg("one", Arg.DataType.STRING, "");
    p.getArg("one").setRestrictedValues(values);
    p.addArg("two", Arg.DataType.INTEGER, "This is a test.");
    p.addNamedArg("testArg", Arg.DataType.STRING, "", "test1", 't');
    p.addNamedArg("testArg2", Arg.DataType.STRING, "", "three");
    p.getArg("testArg2").setRestrictedValues(values);
    p.addNamedArg("testArg3", Arg.DataType.STRING, "NamedDescrip", "one", 'c');
    p.getArg("testArg3").setRestrictedValues(values);
    p.addMutualExclusion(mutex);
    p.setNamedArgToRequired("testArg3");

    x.save(p, "./build/tmp/testSave.xml");
    // read in xml file as string and test against known string
    String actualXMLOutput = "";
    String expectedXLMOutput =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><arguments>    <programname>Test</programname>    <programdescription>Test Program</programdescription>    <mutualexclusion>testArg, testArg2</mutualexclusion><positional>    <position>1</position>    <name>one</name>    <type>string</type>    <restrictedvalues>one, two, three</restrictedvalues></positional><positional>    <position>2</position>    <name>two</name>    <type>integer</type>    <description>This is a test.</description></positional><named>    <name>testArg</name>    <type>string</type>    <shortname>t</shortname>    <default>test1</default></named><named>    <name>testArg2</name>    <type>string</type>    <restrictedvalues>one, two, three</restrictedvalues>    <default>three</default></named><named>    <name>testArg3</name>    <type>string</type>    <restrictedvalues>one, two, three</restrictedvalues>    <description>NamedDescrip</description>    <shortname>c</shortname>    <required>true</required>    <default>one</default></named></arguments>";
    String currentLine = null;
    try {
      FileReader r = new FileReader("./build/tmp/testSave.xml");
      BufferedReader b = new BufferedReader(r);
      while ((currentLine = b.readLine()) != null) actualXMLOutput += currentLine;
      b.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
    assertEquals(expectedXLMOutput, actualXMLOutput);
  }