Commit 686ebdc5 authored by bc1417's avatar bc1417
Browse files

added tests for full name, first name, invalid name, disordered name

parent f22ecce5
......@@ -70,6 +70,24 @@ public class QueryProcessor {
return search(query);
}
private List<String> disambiguation(String query) {
List<String> names = new ArrayList<>();
for(Query q:queriesMap) {
List<String> name = q.getQuery();
boolean found = true;
StringTokenizer queryTokens = new StringTokenizer(query);
for(int i = 0; queryTokens.hasMoreTokens(); i++){
found &= name.contains(queryTokens.nextToken().toLowerCase());
}
if (found) {
String[] option = (String[])name.toArray();
names.add(String.join(" ", option));
}
}
return names;
}
private Query search(String query) {
/*For same surnames, add to a list instead of returning, if list length
is more than 1, then generate choice page, else return answer*/
......
......@@ -28,7 +28,8 @@ public class PDFResultPage implements Page {
writer.println("#Sorry");
writer.println("Sorry, we didn't understand " + query + ".");
} else {
resp.setHeader("Content-Disposition", "inline;filename=\"" + query + ".pdf\"");
resp.setHeader("Content-Disposition", "attachment;filename=\"" + query +
".pdf\"");
File md = File.createTempFile(query, ".md");
md.deleteOnExit();
......
......@@ -41,8 +41,7 @@ public class QueryProcessorTest {
@Test
public void knowsAboutPascal() throws Exception {
assertThat(queryProcessor.process("Pascal").getAnswer(), containsString(
"clarified the concepts " +
"of pressure and vacuum"));
"clarified the concepts of pressure and vacuum"));
}
@Test
......@@ -50,4 +49,86 @@ public class QueryProcessorTest {
assertThat(queryProcessor.process("shakespeare").getAnswer(), containsString(
"playwright"));
}
@Test
public void knowsAboutWilliam() throws Exception {
assertThat(queryProcessor.process("william").getAnswer(), containsString(
"playwright"));
}
@Test
public void knowsAboutIsaac() throws Exception {
assertThat(queryProcessor.process("Isaac").getAnswer(), containsString(
"science " +
"fiction"));
}
@Test
public void knowsAboutAlan() throws Exception {
assertThat(queryProcessor.process("Alan").getAnswer(), containsString(
"logician"));
}
@Test
public void knowsAboutAda() throws Exception {
assertThat(queryProcessor.process("Ada").getAnswer(), containsString(
"Countess of Lovelace"));
}
@Test
public void knowsAboutBlaise() throws Exception {
assertThat(queryProcessor.process("Blaise").getAnswer(), containsString(
"clarified the concepts of pressure and vacuum"));
}
@Test
public void knowsAboutWilliamShakespeare() throws Exception {
assertThat(queryProcessor.process("William Shakespeare").getAnswer(),
containsString(
"playwright"));
}
@Test
public void knowsAboutIsaacAsimov() throws Exception {
assertThat(queryProcessor.process("Isaac Asimov").getAnswer(),
containsString(
"science " +
"fiction"));
}
@Test
public void knowsAboutAlanTuring() throws Exception {
assertThat(queryProcessor.process("Alan Turing").getAnswer(),
containsString(
"logician"));
}
@Test
public void knowsAboutAdaLovelace() throws Exception {
assertThat(queryProcessor.process("Ada Lovelace").getAnswer(),
containsString(
"Countess of Lovelace"));
}
@Test
public void knowsAboutBlaisePascal() throws Exception {
assertThat(queryProcessor.process("Blaise Pascal").getAnswer(),
containsString(
"clarified the concepts of pressure and vacuum"));
}
@Test
public void recognisesDisorderedName() throws Exception {
assertThat(queryProcessor.process("Lovelace Ada Augusta").getAnswer(),
containsString(
"Countess of Lovelace"));
}
@Test
public void recognisesFalseName() throws Exception {
assertThat(queryProcessor.process("William Pascal Lovelace").getAnswer(),
is(""));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment