src/test/java/pt/it/av/tnav/ml/tm/corpus/CorpusDiskCacheTest.java
@org.junit.Test
  public void test() {
    List<SearchEngine.Result> lsr = new ArrayList<>();
    lsr.add(new SearchEngine.Result("banana", "banana", "banana"));
    lsr.add(new SearchEngine.Result("apple", "apple", "apple"));
    lsr.add(new SearchEngine.Result("peach", "peach", "peach"));

    List<String> l = new ArrayList<>(3);
    l.add("banana");
    l.add("apple");
    l.add("peach");

    String tmp = System.getProperty("java.io.tmpdir");
    Corpus c = new CorpusDiskCache(new CorpusSnippet(new MockSearchEngine(lsr)), Paths.get(tmp));

    Iterator<String> it = c.iterator(NGram.Unigram("UNIT_TEST_CORPUS_DISK_CACHE"));

    // Writes the cache
    int idx = 0;
    while (it.hasNext())
      assertTrue(it.next().equals(l.get(idx++)));
    assertTrue(idx == l.size());

    it = c.iterator(NGram.Unigram("UNIT_TEST_CORPUS_DISK_CACHE"));

    // Reads the cache
    idx = 0;
    while (it.hasNext())
      assertTrue(it.next().equals(l.get(idx++)));
    assertTrue(idx == l.size());

    try {
      Files.delete(Paths.get(tmp).resolve("UNIT_TEST_CORPUS_DISK_CACHE.gz"));
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
/**
   * Tests the caching mechanism of the CorpusDiskCache class.
   */
Tests the caching mechanism of the CorpusDiskCache class.
Tests the caching mechanism of the CorpusDiskCache class .
@org.junit.Test
  public void test() {
    List<SearchEngine.Result> lsr = new ArrayList<>();
    lsr.add(new SearchEngine.Result("banana", "banana", "banana"));
    lsr.add(new SearchEngine.Result("apple", "apple", "apple"));
    lsr.add(new SearchEngine.Result("peach", "peach", "peach"));
    List<String> l = new ArrayList<>(3);
    l.add("banana");
    l.add("apple");
    l.add("peach");
    String tmp = System.getProperty("java.io.tmpdir");
    Corpus c = new CorpusDiskCache(new CorpusSnippet(new MockSearchEngine(lsr)), Paths.get(tmp));
    Iterator<String> it = c.iterator(NGram.Unigram("UNIT_TEST_CORPUS_DISK_CACHE"));
    int idx = 0;
    while (it.hasNext())
      assertTrue(it.next().equals(l.get(idx++)));
    assertTrue(idx == l.size());
    it = c.iterator(NGram.Unigram("UNIT_TEST_CORPUS_DISK_CACHE"));
    idx = 0;
    while (it.hasNext())
      assertTrue(it.next().equals(l.get(idx++)));
    assertTrue(idx == l.size());
    try {
      Files.delete(Paths.get(tmp).resolve("UNIT_TEST_CORPUS_DISK_CACHE.gz"));
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
@ org . junit . Test public void test ( ) { List < SearchEngine . Result > lsr = new ArrayList < > ( ) ; lsr . add ( new SearchEngine . Result ( "banana" , "banana" , "banana" ) ) ; lsr . add ( new SearchEngine . Result ( "apple" , "apple" , "apple" ) ) ; lsr . add ( new SearchEngine . Result ( "peach" , "peach" , "peach" ) ) ; List < String > l = new ArrayList < > ( 3 ) ; l . add ( "banana" ) ; l . add ( "apple" ) ; l . add ( "peach" ) ; String tmp = System . getProperty ( "java.io.tmpdir" ) ; Corpus c = new CorpusDiskCache ( new CorpusSnippet ( new MockSearchEngine ( lsr ) ) , Paths . get ( tmp ) ) ; Iterator < String > it = c . iterator ( NGram . Unigram ( "UNIT_TEST_CORPUS_DISK_CACHE" ) ) ; int idx = 0 ; while ( it . hasNext ( ) ) assertTrue ( it . next ( ) . equals ( l . get ( idx ++ ) ) ) ; assertTrue ( idx == l . size ( ) ) ; it = c . iterator ( NGram . Unigram ( "UNIT_TEST_CORPUS_DISK_CACHE" ) ) ; idx = 0 ; while ( it . hasNext ( ) ) assertTrue ( it . next ( ) . equals ( l . get ( idx ++ ) ) ) ; assertTrue ( idx == l . size ( ) ) ; try { Files . delete ( Paths . get ( tmp ) . resolve ( "UNIT_TEST_CORPUS_DISK_CACHE.gz" ) ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } }
Tests the caching mechanism of the CorpusDiskCache class.
Tests the caching mechanism of the CorpusDiskCache class .
// Writes the cache // Reads the cache