Checkpoint: ExchangeServiceTest
Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
parent
ed528ad9a0
commit
d1641277ac
@ -59,10 +59,10 @@ public class MatchData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int compare(MatchData m1) {
|
public int compare(MatchData m1) {
|
||||||
return Float.compare(m1.getExchangesMsValue(), this.getExchangesMsValue());
|
return Long.compare(m1.getExchangesMsValue(), this.getExchangesMsValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getExchangesMsValue(){
|
public long getExchangesMsValue(){
|
||||||
return this.exchangeOne.getDataExchange().getTime() + this.exchangeTwo.getDataExchange().getTime();
|
return this.exchangeOne.getDataExchange().getTime() + this.exchangeTwo.getDataExchange().getTime();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package com.plannaplan.services;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@ -19,8 +20,6 @@ import com.plannaplan.repositories.CommisionRepository;
|
|||||||
import com.plannaplan.types.UserRoles;
|
import com.plannaplan.types.UserRoles;
|
||||||
import com.plannaplan.types.WeekDay;
|
import com.plannaplan.types.WeekDay;
|
||||||
|
|
||||||
import org.apache.commons.compress.utils.Lists;
|
|
||||||
import org.assertj.core.util.Arrays;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -177,10 +176,12 @@ public class ExchangeServiceTest {
|
|||||||
|
|
||||||
assertTrue(listGroupsOfUser1.contains(group2.getId()));
|
assertTrue(listGroupsOfUser1.contains(group2.getId()));
|
||||||
assertTrue(listGroupsOfUser2.contains(group1.getId()));
|
assertTrue(listGroupsOfUser2.contains(group1.getId()));
|
||||||
assertTrue(this.exchangeService.getAllExchanges().size() == 0);
|
int size = this.exchangeService.getAllExchanges().size();
|
||||||
|
assertTrue(this.exchangeService.getAllExchanges().size() == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@DirtiesContext(methodMode = MethodMode.BEFORE_METHOD)
|
||||||
public void shouldSortExchanges() throws Exception{
|
public void shouldSortExchanges() throws Exception{
|
||||||
final List<MatchData> listMatrix = new ArrayList<>();
|
final List<MatchData> listMatrix = new ArrayList<>();
|
||||||
final Exchange exchange1 = new Exchange(null, null);
|
final Exchange exchange1 = new Exchange(null, null);
|
||||||
@ -192,20 +193,13 @@ public class ExchangeServiceTest {
|
|||||||
final Exchange exchange4 = new Exchange(null, null);
|
final Exchange exchange4 = new Exchange(null, null);
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
|
|
||||||
listMatrix.add(new MatchData(exchange1, exchange3));
|
|
||||||
listMatrix.add(new MatchData(exchange2, exchange4));
|
listMatrix.add(new MatchData(exchange2, exchange4));
|
||||||
|
listMatrix.add(new MatchData(exchange1, exchange3));
|
||||||
|
|
||||||
Set<MatchData> filterMatches = new TreeSet<>((m1, m2) -> m1.compare(m2));
|
final List<MatchData> matchDataListSorted = listMatrix.stream().sorted((m1, m2) -> -1 * m1.compare(m2)).collect(Collectors.toList());
|
||||||
filterMatches.addAll(listMatrix);
|
|
||||||
|
|
||||||
Iterator<MatchData> iterator = filterMatches.iterator();
|
assertTrue(listMatrix.get(0).equals(matchDataListSorted.get(1)));
|
||||||
|
assertTrue(listMatrix.get(1).equals(matchDataListSorted.get(0)));
|
||||||
while (iterator.hasNext()) {
|
assertTrue(matchDataListSorted.size() == 2);
|
||||||
MatchData matchData = iterator.next();
|
|
||||||
System.out.println(matchData.getExchangesMsValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
final Set<MatchData> uniqList = this.exchangeService.getMatches();
|
|
||||||
assertTrue(uniqList.size() == 2);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user