Index: voting/src/test/java/geniusweb/voting/CollectedVotesWithValueTest.java
===================================================================
--- voting/src/test/java/geniusweb/voting/CollectedVotesWithValueTest.java	(revision 30)
+++ voting/src/test/java/geniusweb/voting/CollectedVotesWithValueTest.java	(revision 30)
@@ -0,0 +1,372 @@
+package geniusweb.voting;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import geniusweb.actions.PartyId;
+import geniusweb.actions.VoteWithValue;
+import geniusweb.actions.VotesWithValue;
+import geniusweb.issuevalue.Bid;
+import tudelft.utilities.immutablelist.Tuple;
+import tudelft.utilities.junit.GeneralTests;
+
+public class CollectedVotesWithValueTest
+		extends GeneralTests<CollectedVotesWithValue> {
+
+	private final Bid bidA = mock(Bid.class), bidB = mock(Bid.class);
+	private final Bid a = mock(Bid.class), b = mock(Bid.class),
+			c = mock(Bid.class), d = mock(Bid.class);
+	private final PartyId party1 = new PartyId("party1");
+	private final PartyId party2 = new PartyId("party2");
+	private final PartyId party3 = new PartyId("party3");
+	private final PartyId party4 = new PartyId("party4");
+
+	private final PartyId partyP = new PartyId("partyP");
+	private final PartyId partyQ = new PartyId("partyQ");
+	private final PartyId partyR = new PartyId("partyR");
+	private final PartyId partyS = new PartyId("partyS");
+
+	private final VoteWithValue votePA2 = new VoteWithValue(partyP, bidA, 2, 9,
+			100);
+	private final VoteWithValue voteQA2 = new VoteWithValue(partyQ, bidA, 2, 9,
+			50);
+	private final VoteWithValue voteQB3 = new VoteWithValue(partyQ, bidB, 3, 9,
+			50);
+	private final VoteWithValue voteRA4 = new VoteWithValue(partyR, bidA, 4, 9,
+			50);
+
+	private Map<PartyId, Integer> allpowers = new HashMap<>();
+
+	private CollectedVotesWithValue cv1 = new CollectedVotesWithValue(
+			Collections.emptyMap(), Collections.emptyMap());
+	private CollectedVotesWithValue cv1a = new CollectedVotesWithValue(
+			Collections.emptyMap(), Collections.emptyMap());
+
+	private VotesWithValue votes = new VotesWithValue(partyP,
+			Collections.singleton(votePA2));
+	private CollectedVotesWithValue cv2 = new CollectedVotesWithValue(
+			Collections.singletonMap(partyP, votes),
+			Collections.singletonMap(partyP, 1));
+
+	@Override
+	public List<List<CollectedVotesWithValue>> getGeneralTestData() {
+		return Arrays.asList(Arrays.asList(cv1, cv1a), Arrays.asList(cv2));
+	}
+
+	@Override
+	public List<String> getGeneralTestStrings() {
+		return Arrays.asList("CollectedVotesWithValue.\\{\\}.*\\{\\}.*",
+				"CollectedVotesWithValue.\\{partyP=VotesWithValue.*partyP,.VoteWithValue.partyP,bidA.*,2.*\\}.*\\{partyP=1\\}.*");
+	}
+
+	@Before
+	public void before() {
+		allpowers.put(partyP, 1);
+		allpowers.put(partyQ, 1);
+		allpowers.put(partyR, 1);
+		allpowers.put(partyS, 1);
+
+		when(bidA.toString()).thenReturn("bidA");
+		when(bidB.toString()).thenReturn("bidB");
+
+	}
+
+	@Test
+	public void testGetAllBids() {
+		Map<PartyId, VotesWithValue> allvotes = new HashMap<>();
+		allvotes.put(partyP,
+				new VotesWithValue(partyP, Collections.singleton(votePA2)));
+		allvotes.put(partyQ, new VotesWithValue(partyQ,
+				new HashSet<>(Arrays.asList(voteQA2, voteQB3))));
+
+		Map<Bid, Set<VoteWithValue>> allbids = new CollectedVotesWithValue(
+				allvotes, allpowers).getAllBids();
+		assertEquals(2, allbids.size());
+		assertEquals(new HashSet<>(Arrays.asList(votePA2, voteQA2)),
+				allbids.get(bidA));
+		assertEquals(new HashSet<>(Arrays.asList(voteQB3)), allbids.get(bidB));
+	}
+
+	@Test
+	public void getBestCoalitionTest() {
+		// P votes for A, Q votes 50% on A 50% on B.
+		// Only deal is A, 150%
+		Map<PartyId, VotesWithValue> allvotes = new HashMap<>();
+		allvotes.put(partyP,
+				new VotesWithValue(partyP, Collections.singleton(votePA2)));
+		allvotes.put(partyQ, new VotesWithValue(partyQ,
+				new HashSet<>(Arrays.asList(voteQA2, voteQB3))));
+
+		CollectedVotesWithValue cv = new CollectedVotesWithValue(allvotes,
+				allpowers);
+		Tuple<Bid, Integer> best = cv
+				.getBestCoalition(new HashSet<>(Arrays.asList(partyP, partyQ)));
+		assertEquals(bidA, best.get1());
+		assertEquals((Integer) 150, best.get2());
+	}
+
+	@Test
+	public void getBestCoalitionTest2() {
+		// P votes 40% A 60$ B, Q votes 50% on A 50% on B.
+		// Only deal is B, 110%
+		Map<PartyId, VotesWithValue> allvotes = new HashMap<>();
+		allvotes.put(partyP,
+				new VotesWithValue(partyP,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyP, bidA, 2, 9, 40),
+								new VoteWithValue(partyP, bidB, 2, 9, 60)))));
+		allvotes.put(partyQ,
+				new VotesWithValue(partyQ,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyQ, bidA, 2, 9, 50),
+								new VoteWithValue(partyQ, bidB, 2, 9, 50)))));
+
+		CollectedVotesWithValue cv = new CollectedVotesWithValue(allvotes,
+				allpowers);
+		Tuple<Bid, Integer> best = cv
+				.getBestCoalition(new HashSet<>(Arrays.asList(partyP, partyQ)));
+		assertEquals(bidB, best.get1());
+		assertEquals((Integer) 110, best.get2());
+	}
+
+	@Test
+	public void getBestCoalitionTest3() {
+		// P votes 50% A 50$ B, Q votes 50% on A 50% on B.
+		// Both deals A and B are now equivalent so both A and B are good
+		Map<PartyId, VotesWithValue> allvotes = new HashMap<>();
+		allvotes.put(partyP,
+				new VotesWithValue(partyP,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyP, bidA, 2, 9, 50),
+								new VoteWithValue(partyP, bidB, 2, 9, 50)))));
+		allvotes.put(partyQ,
+				new VotesWithValue(partyQ,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyQ, bidA, 2, 9, 50),
+								new VoteWithValue(partyQ, bidB, 2, 9, 50)))));
+
+		CollectedVotesWithValue cv = new CollectedVotesWithValue(allvotes,
+				allpowers);
+		Tuple<Bid, Integer> best = cv
+				.getBestCoalition(new HashSet<>(Arrays.asList(partyP, partyQ)));
+		assertEquals((Integer) 100, best.get2());
+	}
+
+	@Test
+	public void getBestCoalitionTest4() {
+		// P votes 60% A 40% B, Q votes 50% on A 50% on B.
+		// R votes 70% A 30% B.
+		// But P does not want to be in a power-3 team.
+		// therefore there is no 3-team coalition.
+		Map<PartyId, VotesWithValue> allvotes = new HashMap<>();
+		allvotes.put(partyP,
+				new VotesWithValue(partyP,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyP, bidA, 2, 2, 60),
+								new VoteWithValue(partyP, bidB, 2, 2, 40)))));
+		allvotes.put(partyQ,
+				new VotesWithValue(partyQ,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyQ, bidA, 2, 9, 50),
+								new VoteWithValue(partyQ, bidB, 2, 9, 50)))));
+		allvotes.put(partyR,
+				new VotesWithValue(partyR,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyR, bidA, 2, 9, 70),
+								new VoteWithValue(partyR, bidB, 2, 9, 30)))));
+
+		CollectedVotesWithValue cv = new CollectedVotesWithValue(allvotes,
+				allpowers);
+		Tuple<Bid, Integer> best = cv.getBestCoalition(
+				new HashSet<>(Arrays.asList(partyP, partyQ, partyR)));
+		assertNull(best);
+	}
+
+	@Test
+	public void getActiveParties() {
+		Map<PartyId, VotesWithValue> allvotes = new HashMap<>();
+		allvotes.put(partyP, new VotesWithValue(partyP, new HashSet<>(
+				Arrays.asList(new VoteWithValue(partyP, bidB, 2, 2, 100)))));
+		allvotes.put(partyQ, new VotesWithValue(partyQ, new HashSet<>(
+				Arrays.asList(new VoteWithValue(partyQ, bidB, 2, 9, 100)))));
+		allvotes.put(partyR, new VotesWithValue(partyR, new HashSet<>(
+				Arrays.asList(new VoteWithValue(partyR, bidB, 2, 9, 100)))));
+
+		CollectedVotesWithValue cv = new CollectedVotesWithValue(allvotes,
+				allpowers);
+
+		List<PartyId> parties = cv.getParties();
+		assertEquals(Collections.emptySet(), cv.getActiveParties(0));
+		assertEquals(new HashSet<>(Arrays.asList(parties.get(0))),
+				cv.getActiveParties(1));
+		assertEquals(new HashSet<>(Arrays.asList(parties.get(1))),
+				cv.getActiveParties(2));
+		assertEquals(new HashSet<>(Arrays.asList(parties.get(2))),
+				cv.getActiveParties(4));
+		assertEquals(
+				new HashSet<>(Arrays.asList(parties.get(2), parties.get(0))),
+				cv.getActiveParties(5));
+	}
+
+	@Test
+	public void getPartiesTest() {
+		Map<PartyId, VotesWithValue> allvotes = new HashMap<>();
+		allvotes.put(partyP, new VotesWithValue(partyP, new HashSet<>(
+				Arrays.asList(new VoteWithValue(partyP, bidB, 2, 2, 100)))));
+		allvotes.put(partyQ, new VotesWithValue(partyQ, new HashSet<>(
+				Arrays.asList(new VoteWithValue(partyQ, bidB, 2, 9, 100)))));
+		allvotes.put(partyR, new VotesWithValue(partyR, new HashSet<>(
+				Arrays.asList(new VoteWithValue(partyR, bidB, 2, 9, 100)))));
+
+		CollectedVotesWithValue cv = new CollectedVotesWithValue(allvotes,
+				allpowers);
+
+		List<PartyId> parties = cv.getParties();
+		assertEquals(
+				new HashSet<>(Arrays.asList(parties.get(2), parties.get(0))),
+				cv.getParties(new int[] { 1, 3 }));
+
+	}
+
+	@Test
+	public void getCoalitionValuesTest() {
+		// P votes 60% A 40% B, Q votes 50% on A 50% on B.
+		// R votes 70% A 30% B.
+		// But P does not want to be in a power-3 team.
+		// therefore there is no 3-team coalition.
+		// the max 2-team coalition is with P anyway: P+R with bid A, 130.
+
+		// use LinkedHashMap to ensure order of parties
+		// remains P,Q,R in the result.
+		Map<PartyId, VotesWithValue> allvotes = new LinkedHashMap<>();
+		allvotes.put(partyP,
+				new VotesWithValue(partyP,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyP, bidA, 2, 2, 60),
+								new VoteWithValue(partyP, bidB, 2, 2, 40)))));
+		allvotes.put(partyQ,
+				new VotesWithValue(partyQ,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyQ, bidA, 2, 9, 50),
+								new VoteWithValue(partyQ, bidB, 2, 9, 50)))));
+		allvotes.put(partyR,
+				new VotesWithValue(partyR,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyR, bidA, 2, 9, 70),
+								new VoteWithValue(partyR, bidB, 2, 9, 30)))));
+
+		CollectedVotesWithValue cv = new CollectedVotesWithValue(allvotes,
+				allpowers);
+		assertArrayEquals(new double[] { 0d, 0d, 0d, 110d, 0d, 130, 120, 0d },
+				cv.getCoalitionValues(), .0001);
+
+	}
+
+	@Test
+	public void getMaxAgreementsTest() {
+		// P votes 60% A 40% B, Q votes 50% on A 50% on B.
+		// R votes 70% A 30% B.
+		// But P does not want to be in a power-3 team.
+		// therefore there is no 3-team coalition.
+		// the max 2-team coalition is with P anyway: P+R with bid A, 130.
+		Map<PartyId, VotesWithValue> allvotes = new HashMap<>();
+		allvotes.put(partyP,
+				new VotesWithValue(partyP,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyP, bidA, 2, 2, 60),
+								new VoteWithValue(partyP, bidB, 2, 2, 40)))));
+		allvotes.put(partyQ,
+				new VotesWithValue(partyQ,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyQ, bidA, 2, 9, 50),
+								new VoteWithValue(partyQ, bidB, 2, 9, 50)))));
+		allvotes.put(partyR,
+				new VotesWithValue(partyR,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyR, bidA, 2, 9, 70),
+								new VoteWithValue(partyR, bidB, 2, 9, 30)))));
+
+		CollectedVotesWithValue cv = new CollectedVotesWithValue(allvotes,
+				allpowers);
+		Map<PartyId, Bid> best = cv.getMaxAgreements();
+
+		assertEquals(new HashSet<>(Arrays.asList(partyP, partyR)),
+				best.keySet());
+		assertEquals(bidA, best.get(partyP));
+		assertEquals(bidA, best.get(partyR));
+	}
+
+	@Test
+	public void getMaxAgreementsTest2() {
+		Map<PartyId, VotesWithValue> allvotes = new HashMap<>();
+		allvotes.put(partyP,
+				new VotesWithValue(partyP,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyP, bidA, 2, 2, 30),
+								new VoteWithValue(partyP, bidB, 2, 3, 70)))));
+		allvotes.put(partyQ,
+				new VotesWithValue(partyQ,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyQ, bidA, 2, 9, 30),
+								new VoteWithValue(partyQ, bidB, 2, 9, 70)))));
+		allvotes.put(partyR,
+				new VotesWithValue(partyR,
+						new HashSet<>(Arrays.asList(
+								new VoteWithValue(partyR, bidA, 2, 9, 30),
+								new VoteWithValue(partyR, bidB, 2, 9, 70)))));
+
+		allvotes.put(partyS, new VotesWithValue(partyS, new HashSet<>(
+				Arrays.asList(new VoteWithValue(partyS, bidA, 2, 9, 100)))));
+
+		CollectedVotesWithValue cv = new CollectedVotesWithValue(allvotes,
+				allpowers);
+		Map<PartyId, Bid> best = cv.getMaxAgreements();
+		assertEquals(
+				new HashSet<>(Arrays.asList(partyP, partyQ, partyR, partyS)),
+				best.keySet());
+		assertEquals(bidB, best.get(partyP));
+		assertEquals(bidB, best.get(partyQ));
+		assertEquals(bidA, best.get(partyR));
+		assertEquals(bidA, best.get(partyS));
+	}
+
+	@Test
+	public void getMaxAgreementsTest3() {
+		// all vote on bid A, but partyP wants no more than 2 in the coalition.
+		// this deal can still be reached, bu placing partyP,Q in one coalition
+		// and R and S in another coalition.
+		Map<PartyId, VotesWithValue> allvotes = new HashMap<>();
+		allvotes.put(partyP, new VotesWithValue(partyP, new HashSet<>(
+				Arrays.asList(new VoteWithValue(partyP, bidA, 2, 2, 100)))));
+		allvotes.put(partyQ, new VotesWithValue(partyQ, new HashSet<>(
+				Arrays.asList(new VoteWithValue(partyQ, bidA, 2, 9, 100)))));
+		allvotes.put(partyR, new VotesWithValue(partyR, new HashSet<>(
+				Arrays.asList(new VoteWithValue(partyR, bidA, 2, 3, 100)))));
+
+		allvotes.put(partyS, new VotesWithValue(partyS, new HashSet<>(
+				Arrays.asList(new VoteWithValue(partyS, bidA, 2, 9, 100)))));
+
+		CollectedVotesWithValue cv = new CollectedVotesWithValue(allvotes,
+				allpowers);
+		Map<PartyId, Bid> best = cv.getMaxAgreements();
+		assertEquals(
+				new HashSet<>(Arrays.asList(partyP, partyQ, partyR, partyS)),
+				best.keySet());
+	}
+
+}
Index: voting/src/test/java/geniusweb/voting/evaluatorwithvalue/LargestAgreementWithValueTest.java
===================================================================
--- voting/src/test/java/geniusweb/voting/evaluatorwithvalue/LargestAgreementWithValueTest.java	(revision 30)
+++ voting/src/test/java/geniusweb/voting/evaluatorwithvalue/LargestAgreementWithValueTest.java	(revision 30)
@@ -0,0 +1,119 @@
+package geniusweb.voting.evaluatorwithvalue;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import geniusweb.actions.PartyId;
+import geniusweb.actions.VoteWithValue;
+import geniusweb.actions.VotesWithValue;
+import geniusweb.inform.Agreements;
+import geniusweb.issuevalue.Bid;
+import geniusweb.voting.CollectedVotesWithValue;
+import geniusweb.voting.VotingEvaluatorWithValue;
+import tudelft.utilities.junit.GeneralTests;
+
+public class LargestAgreementWithValueTest
+		extends GeneralTests<LargestAgreementWithValue> {
+	private final ObjectMapper jackson = new ObjectMapper();
+
+	private LargestAgreementWithValue lal1 = new LargestAgreementWithValue();
+	private LargestAgreementWithValue lal1a = new LargestAgreementWithValue();
+	private PartyId party1 = new PartyId("party1");
+	private PartyId party2 = new PartyId("party2");
+	private PartyId party3 = new PartyId("party3");
+	private PartyId party4 = new PartyId("party4");
+	private VotesWithValue votes1 = mock(VotesWithValue.class);
+	private LargestAgreementWithValue lal2 = new LargestAgreementWithValue(
+			new CollectedVotesWithValue(
+					Collections.singletonMap(party1, votes1),
+					Collections.singletonMap(party1, 1)));
+
+	private String lalstring = "{\"LargestAgreementWithValue\":{}}";
+
+	@Override
+	public List<List<LargestAgreementWithValue>> getGeneralTestData() {
+		return Arrays.asList(Arrays.asList(lal1, lal1a), Arrays.asList(lal2));
+	}
+
+	@Override
+	public List<String> getGeneralTestStrings() {
+		return Arrays.asList("LargestAgreement", "LargestAgreement");
+	}
+
+	@Test
+	public void serializeTest() throws JsonProcessingException {
+		// we use lal2 to also check we don't serialize the contents
+		System.out.println(jackson.writeValueAsString(lal2));
+		assertEquals(lalstring, jackson.writeValueAsString(lal2));
+	}
+
+	@Test
+	public void deserializeTest() throws IOException {
+		VotingEvaluatorWithValue eval = jackson.readValue(lalstring,
+				VotingEvaluatorWithValue.class);
+		// it should deserialize as the empty lal1 because we ignore the fields.
+		assertEquals(lal1, eval);
+	}
+
+	@Test
+	public void testCollectVotes() {
+		Bid bid1 = mock(Bid.class);
+		when(bid1.toString()).thenReturn("bid1");
+		Bid bid2 = mock(Bid.class);
+		when(bid2.toString()).thenReturn("bid2");
+
+		VotesWithValue votes1 = new VotesWithValue(party1,
+				new HashSet<>(Arrays.asList(
+						new VoteWithValue(party1, bid1, 2, 99, 40),
+						new VoteWithValue(party1, bid2, 2, 99, 60))));
+		VotesWithValue votes2 = new VotesWithValue(party2, new HashSet<>(
+				Arrays.asList(new VoteWithValue(party2, bid1, 2, 99, 100))));
+		VotesWithValue votes3 = new VotesWithValue(party3, new HashSet<>(
+				Arrays.asList(new VoteWithValue(party3, bid1, 2, 99, 100))));
+		VotesWithValue votes4 = new VotesWithValue(party4, new HashSet<>(
+				Arrays.asList(new VoteWithValue(party4, bid1, 2, 99, 100))));
+		HashMap<PartyId, VotesWithValue> votesmap = new HashMap<>();
+		votesmap.put(party1, votes1);
+		votesmap.put(party2, votes2);
+		votesmap.put(party3, votes3);
+		votesmap.put(party4, votes4);
+		HashMap<PartyId, Integer> powermap = new HashMap<>();
+		powermap.put(party1, 1);
+		powermap.put(party2, 1);
+		powermap.put(party3, 1);
+		powermap.put(party4, 4);
+
+		CollectedVotesWithValue votes = new CollectedVotesWithValue(votesmap,
+				powermap);
+
+		LargestAgreementWithValue la = new LargestAgreementWithValue(votes);
+		Agreements agreement = la.getAgreements();
+		assertEquals(
+				new HashSet<PartyId>(
+						Arrays.asList(party1, party2, party3, party4)),
+				agreement.getMap().keySet());
+	}
+
+	@Test
+	public void testEmptyCollectVotes() {
+
+		CollectedVotesWithValue votes = new CollectedVotesWithValue(
+				Collections.emptyMap(), Collections.emptyMap());
+
+		LargestAgreementWithValue la = new LargestAgreementWithValue(votes);
+		Agreements agreement = la.getAgreements();
+	}
+}
