package com.scarytom.pronet;

import static org.junit.Assert.assertEquals;
import junit.framework.Assert;

import org.junit.Test;

import com.google.common.collect.Sets;
import com.scarytom.Network;
import com.scarytom.NetworkBuilder;

public class KudosProviderTest {

	@Test
	public void testKudosForSingleProgrammer() {
		Programmer bill = new Programmer("Bill", Sets.<String> newHashSet());
		Network network = new NetworkBuilder().withProgrammer(bill).build();
		KudosProvider kudosProvider = new KudosProvider(network);
		Assert.assertEquals(1.0, kudosProvider.kudosFor(bill), 0.01);
	}

	@Test
	public void twoProgrammersPassAllKudosToEachOther() {
		Programmer programmer2 = new Programmer("programmer2",
				Sets.<String> newHashSet());
		Programmer programmer = new Programmer("programmer1",
				Sets.<String> newHashSet());
		programmer.addRecommendation(programmer2);
		// calculate the kudos..
		assertEquals(1, programmer.kudos(), 0.001);
	}

	@Test
	public void severalProgrammersPassKudosToEachOther() {
		Programmer a = new Programmer("programmer2", Sets.<String> newHashSet());
		Programmer b = new Programmer("programmer2", Sets.<String> newHashSet());
		Programmer c = new Programmer("programmer2", Sets.<String> newHashSet());
		Programmer d = new Programmer("programmer2", Sets.<String> newHashSet());

		a.addRecommendation(b);
		a.addRecommendation(c);
		b.addRecommendation(c);
		c.addRecommendation(a);
		d.addRecommendation(c);

		// A=1.49, B=0.78, C=1.59, D=0.15

		assertEquals(1.49, a.kudos(), 0.001);
		assertEquals(0.78, b.kudos(), 0.001);
		assertEquals(1.59, c.kudos(), 0.001);
		assertEquals(0.15, d.kudos(), 0.001);
	}

}

@@ -268,45 +268,53 @@
 %7B%0A%0A%09
-@Test%0A%09public void testKudosForSingle
+private KudosProvider getKudosProvider(final 
 Prog
@@ -319,24 +319,21 @@
 ogrammer
-() %7B%0A%09%09P
+... p
 rogramme
@@ -337,67 +337,164 @@
 mmer
- bill = new Programmer(%22Bill%22, Sets.%3CString%3E newHashSet());
+s) %7B%0A%09%09NetworkBuilder networkBuilder = new NetworkBuilder();%0A%09%09for (Programmer programmer : programmers) %7B%0A%09%09%09networkBuilder.withProgrammer(programmer);%0A%09%09%7D
 %0A%09%09N
@@ -508,28 +508,24 @@
 network = ne
-w Ne
 tworkBuilder
@@ -528,31 +528,8 @@
 lder
-().withProgrammer(bill)
 .bui
@@ -594,16 +594,169 @@
 twork);%0A
+%09%09return kudosProvider;%0A%09%7D%0A%0A%09@Test%0A%09public void testKudosForSingleProgrammer() %7B%0A%09%09Programmer bill = new Programmer(%22Bill%22, Sets.%3CString%3E newHashSet());%0A
 %09%09Assert
@@ -774,17 +774,20 @@
 ls(1.0, 
-k
+getK
 udosProv
@@ -790,16 +790,22 @@
 Provider
+(bill)
 .kudosFo
@@ -900,25 +900,16 @@
 rammer p
-rogrammer
 2 = new 
@@ -981,25 +981,17 @@
 rammer p
-rogrammer
+1
  = new P
@@ -1051,25 +1051,17 @@
 ());%0A%09%09p
-rogrammer
+1
 .addReco
@@ -1076,83 +1076,67 @@
 on(p
-rogrammer2);%0A%09%09// calculate the kudos..%0A%09%09assertEquals(1, programmer.kudos(
+2);%0A%0A%09%09assertEquals(1, getKudosProvider(p2, p1).kudosFor(p1
 ), 0
@@ -1682,16 +1682,79 @@
 D=0.15%0A%0A
+%09%09KudosProvider kudosProvider = getKudosProvider(a, b, c, d);%0A%0A
 %09%09assert
@@ -1770,16 +1770,32 @@
 49, 
-a
+kudosProvider
 .kudos
-(
+For(a
 ), 0
@@ -1826,16 +1826,32 @@
 78, 
-b
+kudosProvider
 .kudos
-(
+For(b
 ), 0
@@ -1882,16 +1882,32 @@
 59, 
-c
+kudosProvider
 .kudos
-(
+For(c
 ), 0
@@ -1938,16 +1938,32 @@
 15, 
-d
+kudosProvider
 .kudos
-(
+For(d
 ), 0
@@ -1972,11 +1972,10 @@
 01);%0A%09%7D%0A
-%0A
 %7D%0A

Fix compilation errors of previous commit (mental note: don't commit on a plane)