package edu.brown.cs.student; import edu.brown.cs.student.term.DatabaseQuerier; import edu.brown.cs.student.term.hub.Holder; import edu.brown.cs.student.term.hub.HubSearch; import edu.brown.cs.student.term.hub.LinkMapper; import org.junit.After; import org.junit.Before; import org.junit.Test; import java.time.Instant; import java.util.Map; import java.util.Set; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class LinkMapperTest { /** these should span the entire mock dataset */ //12 am on 3/11 in UTC private Instant start = Instant.parse("2021-03-11T05:00:00.00Z"); //12 am on 3/28 in UTC private Instant end = Instant.parse("2021-03-28T05:00:00.00Z"); private DatabaseQuerier db; @Before public void setUp() { try{ db = new DatabaseQuerier("data/lil_mock.sqlite3"); } catch(Exception e){ System.out.println("DBQuerier Test, couldn't connect to db???"); } } @After public void tearDown() { db = null; } @Test public void testBasicMapper(){ setUp(); LinkMapper lm = new LinkMapper(db); Map> linkMap = lm.makeFollowerLinks(start, end); //should be one for each person in little mock (6) assertEquals(6, linkMap.keySet().size()); for(Holder h: linkMap.keySet()){ //didn't follow anyone elses trades if(h.getName().equals("Don") || h.getName().equals("Jane")){ assertTrue(linkMap.get(h).isEmpty()); //biggest follower } else if(h.getName().equals("Midge")){ assertEquals(4, linkMap.get(h).size()); } else if(h.getName().equals("Nancy") || h.getName().equals("Mitch")){ assertEquals(2, linkMap.get(h).size()); } else { //should be Bob, only followed Mitch assertEquals(1, linkMap.get(h).size()); } } tearDown(); } @Test public void testBadDate(){ setUp(); LinkMapper lm = new LinkMapper(db); Map> linkMap = lm.makeFollowerLinks(end, start); assertTrue(linkMap.isEmpty()); tearDown(); } @Test public void testEmptyDB(){ try{ db = new DatabaseQuerier("data/empty.sqlite3"); } catch(Exception e){ System.out.println("DBQuerier Test, couldn't connect to db???"); } LinkMapper lm = new LinkMapper(db); Map> linkMap = lm.makeFollowerLinks(start, end); //should be one for each person in little mock (6) assertTrue(linkMap.isEmpty()); } }