@Test public void testMinDistance() { MinDistance md = new MinDistance(); Person ThiagoCassioKrug = null; Person thiago = new Person(); thiago.setName("Thiago Cassio Krug"); thiago.setId(4); int i = persons.indexOf(thiago); if (i >= 0) { ThiagoCassioKrug = persons.get(i); md.computeScore(ThiagoCassioKrug, true); } else { fail("Não encontrou a pessoa da pesquisa!"); } Collections.sort(ThiagoCassioKrug.getRelationships()); List<Relationship> relationships = ThiagoCassioKrug.getRelationships(); int j = 0; assertEquals(relationships.get(j).getPerson2().getName(), "Marcelo Maia Lopes"); assertEquals(relationships.get(j++).getScore(), 0.99998153499579921154432062633294d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Bruno Vicelli"); assertEquals(relationships.get(j++).getScore(), 0.99998153499579921154432062633294d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafael Tavares Amorim"); assertEquals(relationships.get(j++).getScore(), 0.99991690748109645194944281849824d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Helison Reus Teixeira"); assertEquals(relationships.get(j++).getScore(), 0.99990767497899605772160313166471d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Thiago Aquino de Lima"); assertEquals(relationships.get(j++).getScore(), 0.99989844247689566349376344483118d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Mateus Henrique Dal Forno"); assertEquals(relationships.get(j++).getScore(), 0.9998061174558917212153665764959d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafhael Rodrigues Cunha"); assertEquals(relationships.get(j++).getScore(), 0.99959376990758265397505377932473d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Renan Marcel Uchôa"); assertEquals(relationships.get(j++).getScore(), 0.9993260273466712213677028611524d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Juliano Rodovalho Macedo"); assertEquals(relationships.get(j++).getScore(), 0.99711945934467700091401770793903d, delta); }
@Test public void testMaxDistance() { MaxDistance md = new MaxDistance(); Person ThiagoCassioKrug = null; Person thiago = new Person(); thiago.setName("Thiago Cassio Krug"); thiago.setId(4); int i = persons.indexOf(thiago); if (i >= 0) { ThiagoCassioKrug = persons.get(i); md.computeScore(ThiagoCassioKrug, true); } else { fail("Não encontrou a pessoa da pesquisa!"); } Collections.sort(ThiagoCassioKrug.getRelationships()); List<Relationship> relationships = ThiagoCassioKrug.getRelationships(); int j = 0; assertEquals(relationships.get(j).getPerson2().getName(), "Marcelo Maia Lopes"); assertEquals(relationships.get(j++).getScore(), 0.98147960078660917895358821194132d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Bruno Vicelli"); assertEquals(relationships.get(j++).getScore(), 0.98142420577400681358655009094015d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Helison Reus Teixeira"); assertEquals(relationships.get(j++).getScore(), 0.97165621855178972053216142106672d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Renan Marcel Uchôa"); assertEquals(relationships.get(j++).getScore(), 0.87781706720338278876958444508046d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Juliano Rodovalho Macedo"); assertEquals(relationships.get(j++).getScore(), 0.80018095704116772686565786193716d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Mateus Henrique Dal Forno"); assertEquals(relationships.get(j++).getScore(), 0.78367324328566284748829780358775d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafael Tavares Amorim"); assertEquals(relationships.get(j++).getScore(), 0.62412637448875019619066963337734d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Thiago Aquino de Lima"); assertEquals(relationships.get(j++).getScore(), 0.24201157755763389436171096728925d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafhael Rodrigues Cunha"); assertEquals(relationships.get(j++).getScore(), 0.0d, delta); }
@Test public void testRelationshipOccurrenceNumber() { RelationshipOccurrenceNumber ron = new RelationshipOccurrenceNumber(); Person ThiagoCassioKrug = null; Person thiago = new Person(); thiago.setName("Thiago Cassio Krug"); thiago.setId(4); int i = persons.indexOf(thiago); if (i >= 0) { ThiagoCassioKrug = persons.get(i); ron.computeScore(ThiagoCassioKrug, true); } else { fail("Não encontrou a pessoa da pesquisa!"); } Collections.sort(ThiagoCassioKrug.getRelationships()); List<Relationship> relationships = ThiagoCassioKrug.getRelationships(); int j = 0; assertEquals(relationships.get(j).getPerson2().getName(), "Rafhael Rodrigues Cunha"); assertEquals(relationships.get(j++).getScore(), 1.0d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Helison Reus Teixeira"); assertEquals(relationships.get(j++).getScore(), 0.9333333333333333d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafael Tavares Amorim"); assertEquals(relationships.get(j++).getScore(), 0.9333333333333333d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Bruno Vicelli"); assertEquals(relationships.get(j++).getScore(), 0.8d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Mateus Henrique Dal Forno"); assertEquals(relationships.get(j++).getScore(), 0.8d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Renan Marcel Uchôa"); assertEquals(relationships.get(j++).getScore(), 0.7333333333333333d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Marcelo Maia Lopes"); assertEquals(relationships.get(j++).getScore(), 0.6666666666666666d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Thiago Aquino de Lima"); assertEquals(relationships.get(j++).getScore(), 0.6666666666666666d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Juliano Rodovalho Macedo"); assertEquals(relationships.get(j++).getScore(), 0.3333333333333333d, delta); }
@Test public void testAverageDistance() { AverageDistance ad = new AverageDistance(); Person ThiagoCassioKrug = null; Person thiago = new Person(); thiago.setName("Thiago Cassio Krug"); thiago.setId(4); int i = persons.indexOf(thiago); if (i >= 0) { ThiagoCassioKrug = persons.get(i); ad.computeScore(ThiagoCassioKrug, true); } else { fail("Não encontrou a pessoa da pesquisa!"); } Collections.sort(ThiagoCassioKrug.getRelationships()); List<Relationship> relationships = ThiagoCassioKrug.getRelationships(); int j = 0; assertEquals(relationships.get(j).getPerson2().getName(), "Marcelo Maia Lopes"); assertEquals(relationships.get(j++).getScore(), 0.99972302493698817316480939499414d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Bruno Vicelli"); assertEquals(relationships.get(j++).getScore(), 0.99969224992998685907201043888237d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Helison Reus Teixeira"); assertEquals(relationships.get(j++).getScore(), 0.99966455242368567638849137838179d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Mateus Henrique Dal Forno"); assertEquals(relationships.get(j++).getScore(), 0.99941835236767516364609972948769d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Renan Marcel Uchôa"); assertEquals(relationships.get(j++).getScore(), 0.99847355965273482099717177685658d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafhael Rodrigues Cunha"); assertEquals(relationships.get(j++).getScore(), 0.99832583961912851335173678752012d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Rafael Tavares Amorim"); assertEquals(relationships.get(j++).getScore(), 0.99739643440768882774920831294489d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Thiago Aquino de Lima"); assertEquals(relationships.get(j++).getScore(), 0.98303066113947540923065559997415d, delta); assertEquals(relationships.get(j).getPerson2().getName(), "Juliano Rodovalho Macedo"); assertEquals(relationships.get(j++).getScore(), 0.97067295707809773526723477329591d, delta); }
public ArrayList<Person> getAllPersons() throws SQLException { conn = DBTool.getInstance(); System.out.println("Getting all persons..."); if (conn.isValid(10000)) { Statement s = conn.createStatement(); ArrayList<Person> persons = new ArrayList<>(); ResultSet rs = s.executeQuery("SELECT * FROM person"); while (rs.next()) { int idperson = rs.getInt("idperson"); String firstname = rs.getString("firstname"); String middlename = rs.getString("middlename"); String lastname = rs.getString("lastname"); String address = rs.getString("address"); ADate birthday = new ADate(rs.getString("birthday")); ADate expirationDate = new ADate(rs.getString("expirationdate")); File picturePath = new File(rs.getString("picturepath")); ADate quarantineExpirationDate = null; if (!rs.getString("quarantineexpirationdate").isEmpty()) { quarantineExpirationDate = new ADate(rs.getString("quarantineexpirationdate")); } ADate creationDate = new ADate(rs.getString("creationdate")); boolean oneOne = false; if (rs.getInt("oneone") == 1) { oneOne = true; } boolean quarantine = false; if (rs.getInt("quarantine") == 1) { quarantine = true; } boolean enrolled = false; if (rs.getInt("enrolled") == 1) { enrolled = true; } boolean hone = false; if (rs.getInt("hone") == 1) { hone = true; } Statement s2 = conn.createStatement(); ArrayList<Guest> guests = new ArrayList<>(); ResultSet rsGuest = s2.executeQuery("SELECT * FROM guest WHERE idperson = " + idperson + ";"); while (rsGuest.next()) { Guest g = new Guest( rsGuest.getString("firstname"), rsGuest.getString("middlename"), rsGuest.getString("lastname"), new ADate(rsGuest.getString("birthday")), new ADate(rsGuest.getString("creationdate"))); g.setId(rsGuest.getInt("idguest")); guests.add(g); } Person p = new Person( firstname, middlename, lastname, address, birthday, expirationDate, picturePath, creationDate, oneOne); p.setId(idperson); p.setQuarantine(quarantine); p.setQuarantineExpirationDate(quarantineExpirationDate); p.setEnrolled(enrolled); p.setHone(hone); p.setGuests(guests); persons.add(p); rsGuest.close(); s2.close(); } System.out.println("Get complete!"); rs.close(); s.close(); conn.close(); return persons; } else { System.out.println("Connection invalid"); conn.close(); return null; } }