mas01mj@725
|
1 import junit.framework.*;
|
mas01mj@725
|
2 import java.io.File;
|
mas01mj@727
|
3 import java.util.Vector;
|
mas01mj@725
|
4 import org.omras2.*;
|
mas01mj@725
|
5
|
mas01mj@725
|
6 public class TestQuery extends TestCase
|
mas01mj@725
|
7 {
|
mas01mj@725
|
8 File testDBFile;
|
mas01mj@725
|
9 File testFeatureFile;
|
mas01mj@725
|
10 protected void setUp()
|
mas01mj@725
|
11 {
|
mas01mj@725
|
12 testDBFile = new File("testfiles/test.adb");
|
mas01mj@725
|
13 testFeatureFile = new File("testfiles/testfeature");
|
mas01mj@725
|
14 if(testDBFile.exists())
|
mas01mj@725
|
15 testDBFile.delete();
|
mas01mj@725
|
16 }
|
mas01mj@725
|
17
|
mas01mj@725
|
18 public void testQuery()
|
mas01mj@725
|
19 {
|
mas01mj@725
|
20 // Insert the same feature twice
|
mas01mj@725
|
21 AudioDB testDB = new AudioDB(testDBFile);
|
mas01mj@725
|
22 assertTrue("DB created", testDB.create(1, 2, 1));
|
mas01mj@725
|
23 testDB.open(AudioDB.Mode.O_RDWR);
|
mas01mj@725
|
24 assertTrue("Insert feature file", testDB.insert("feat1", testFeatureFile));
|
mas01mj@725
|
25 assertTrue("Insert feature file again", testDB.insert("feat2", testFeatureFile));
|
mas01mj@725
|
26 testDB.close();
|
mas01mj@725
|
27
|
mas01mj@725
|
28 testDB.open(AudioDB.Mode.O_RDONLY);
|
mas01mj@725
|
29 Status status = testDB.getStatus();
|
mas01mj@725
|
30 assertEquals("Two features", 2, status.getNumFiles());
|
mas01mj@726
|
31
|
mas01mj@726
|
32 Query query = new Query();
|
mas01mj@726
|
33 query.setSeqLength(1);
|
mas01mj@726
|
34 query.setSeqStart(0);
|
mas01mj@727
|
35 query.setIncludeKeys(new String[]{"feat1"});
|
mas01mj@727
|
36 query.setExcludeKeys(new String[]{"feat2"});
|
mas01mj@727
|
37 Vector<Result> results = testDB.query("feat1", query);
|
mas01mj@727
|
38 System.out.println(results.size());
|
mas01mj@727
|
39 for(Result result: results)
|
mas01mj@727
|
40 {
|
mas01mj@727
|
41 System.out.println(result.getKey());
|
mas01mj@727
|
42 System.out.println(result.getDistance());
|
mas01mj@727
|
43 System.out.println(result.getQpos());
|
mas01mj@727
|
44 System.out.println(result.getIpos());
|
mas01mj@727
|
45 }
|
mas01mj@725
|
46 }
|
mas01mj@727
|
47 /*
|
mas01mj@727
|
48 public void testAdvanced()
|
mas01mj@727
|
49 {
|
mas01mj@727
|
50 AudioDB testDB = new AudioDB(new File("testfiles/9.adb"));
|
mas01mj@727
|
51 testDB.open(AudioDB.Mode.O_RDONLY);
|
mas01mj@727
|
52 Status status = testDB.getStatus();
|
mas01mj@727
|
53 System.out.println(status.getNumFiles());
|
mas01mj@727
|
54 Query query = new Query();
|
mas01mj@727
|
55 query.setSeqLength(16);
|
mas01mj@727
|
56 query.setSeqStart(0);
|
mas01mj@727
|
57 query.setExcludeKeys(new String[]{"KSA_CHARM_27", "KSA_CHARM_336", "KSA_CHARM_300"});
|
mas01mj@727
|
58 query.setSeqStart(0);
|
mas01mj@727
|
59 Vector<Result> results = testDB.query("KSA_CHARM_27", query);
|
mas01mj@727
|
60 System.out.println(results.size());
|
mas01mj@727
|
61 for(Result result: results)
|
mas01mj@727
|
62 {
|
mas01mj@727
|
63 System.out.print(result.getKey());
|
mas01mj@727
|
64 System.out.print(" "+result.getDistance());
|
mas01mj@727
|
65 System.out.print(" "+result.getQpos());
|
mas01mj@727
|
66 System.out.println(" "+result.getIpos());
|
mas01mj@727
|
67 }
|
mas01mj@727
|
68
|
mas01mj@727
|
69 }*/
|
mas01mj@725
|
70
|
mas01mj@725
|
71 }
|