def test_analyse_cooperation_ratio(self): tf = TransitiveFingerprint(axl.TitForTat) path = pathlib.Path("test_outputs/test_fingerprint.csv") filename = axl_filename(path) with open(filename, "w") as f: f.write( """Interaction index,Player index,Opponent index,Repetition,Player name,Opponent name,Actions 0,0,1,0,Player0,Player1,CCC 0,1,0,0,Player1,Player0,DDD 1,0,1,1,Player0,Player1,CCC 1,1,0,1,Player1,Player0,DDD 2,0,2,0,Player0,Player2,CCD 2,2,0,0,Player2,Player0,DDD 3,0,2,1,Player0,Player2,CCC 3,2,0,1,Player2,Player0,DDD 4,0,3,0,Player0,Player3,CCD 4,3,0,0,Player3,Player0,DDD 5,0,3,1,Player0,Player3,DCC 5,3,0,1,Player3,Player0,DDD 6,0,4,2,Player0,Player4,DDD 6,4,0,2,Player4,Player0,DDD 7,0,4,3,Player0,Player4,DDD 7,4,0,3,Player4,Player0,DDD""") data = tf.analyse_cooperation_ratio(filename) expected_data = np.array([[1, 1, 1], [1, 1, 1 / 2], [1 / 2, 1, 1 / 2], [0, 0, 0]]) self.assertTrue(np.array_equal(data, expected_data))
def test_serial_fingerprint(self): strategy = axl.TitForTat() tf = TransitiveFingerprint(strategy) tf.fingerprint(repetitions=1, progress_bar=False, filename="test_outputs/tran_fin.csv") self.assertEqual(tf.data.shape, (50, 50))
def test_serial_fingerprint(self): strategy = axl.TitForTat() tf = TransitiveFingerprint(strategy) tf.fingerprint( repetitions=1, progress_bar=False, filename="test_outputs/tran_fin.csv" ) self.assertEqual(tf.data.shape, (50, 50))
def test_analyse_cooperation_ratio(self): tf = TransitiveFingerprint(axl.TitForTat) filename = "test_outputs/test_fingerprint.csv" with open(filename, "w") as f: f.write( """Interaction index,Player index,Opponent index,Repetition,Player name,Opponent name,Actions 0,0,1,0,Player0,Player1,CCC 0,1,0,0,Player1,Player0,DDD 1,0,1,1,Player0,Player1,CCC 1,1,0,1,Player1,Player0,DDD 2,0,2,0,Player0,Player2,CCD 2,2,0,0,Player2,Player0,DDD 3,0,2,1,Player0,Player2,CCC 3,2,0,1,Player2,Player0,DDD 4,0,3,0,Player0,Player3,CCD 4,3,0,0,Player3,Player0,DDD 5,0,3,1,Player0,Player3,DCC 5,3,0,1,Player3,Player0,DDD 6,0,4,2,Player0,Player4,DDD 6,4,0,2,Player4,Player0,DDD 7,0,4,3,Player0,Player4,DDD 7,4,0,3,Player4,Player0,DDD""" ) data = tf.analyse_cooperation_ratio(filename) expected_data = np.array( [[1, 1, 1], [1, 1, 1 / 2], [1 / 2, 1, 1 / 2], [0, 0, 0]] ) self.assertTrue(np.array_equal(data, expected_data))
def test_fingerprint_with_filename(self): filename = "test_outputs/test_fingerprint.csv" strategy = axl.TitForTat() tf = TransitiveFingerprint(strategy) tf.fingerprint(turns=1, repetitions=1, progress_bar=False, filename=filename) with open(filename, "r") as out: data = out.read() self.assertEqual(len(data.split("\n")), 102)
def test_fingerprint_with_filename(self): path = pathlib.Path("test_outputs/test_fingerprint.csv") filename = axl_filename(path) strategy = axl.TitForTat() tf = TransitiveFingerprint(strategy) tf.fingerprint(turns=1, repetitions=1, progress_bar=False, filename=filename) with open(filename, "r") as out: data = out.read() self.assertEqual(len(data.split("\n")), 102)
def test_fingerprint_with_filename(self): filename = "test_outputs/test_fingerprint.csv" strategy = axl.TitForTat() tf = TransitiveFingerprint(strategy) tf.fingerprint(turns=1, repetitions=1, progress_bar=False, filename=filename) with open(filename, 'r') as out: data = out.read() self.assertEqual(len(data.split("\n")), 50 + 1)
def test_analyse_cooperation_ratio(self): tf = TransitiveFingerprint(axl.TitForTat) filename = "test_outputs/test_fingerprint.csv" with open(filename, "w") as f: f.write("""0,1,Player0,Player1,CCC,DDD 0,1,Player0,Player1,CCC,DDD 0,2,Player0,Player2,CCD,DDD 0,2,Player0,Player2,CCC,DDD 0,3,Player0,Player3,CCD,DDD 0,3,Player0,Player3,DCC,DDD 0,4,Player0,Player3,DDD,DDD 0,4,Player0,Player3,DDD,DDD""") data = tf.analyse_cooperation_ratio(filename) expected_data = np.array([[1, 1, 1], [1, 1, 1 / 2], [1 / 2, 1, 1 / 2], [0, 0, 0]]) self.assertTrue(np.array_equal(data, expected_data))
def test_plot(self): """ Test that plot is created with various arguments. """ tf = TransitiveFingerprint(axl.TitForTat) tf.fingerprint(turns=10, repetitions=2, progress_bar=False) p = tf.plot() self.assertIsInstance(p, matplotlib.pyplot.Figure) p = tf.plot(cmap="jet") self.assertIsInstance(p, matplotlib.pyplot.Figure) p = tf.plot(interpolation="bicubic") self.assertIsInstance(p, matplotlib.pyplot.Figure) p = tf.plot(title="Title") self.assertIsInstance(p, matplotlib.pyplot.Figure) p = tf.plot(colorbar=False) self.assertIsInstance(p, matplotlib.pyplot.Figure) p = tf.plot(labels=False) self.assertIsInstance(p, matplotlib.pyplot.Figure) p = tf.plot(display_names=True) self.assertIsInstance(p, matplotlib.pyplot.Figure)
def test_plot_with_axis(self): fig, axarr = matplotlib.pyplot.subplots(2, 2) tf = TransitiveFingerprint(axl.TitForTat) tf.fingerprint(turns=10, repetitions=2, progress_bar=False) p = tf.plot(ax=axarr[0, 0]) self.assertIsInstance(p, matplotlib.pyplot.Figure)
def test_parallel_fingerprint(self): strategy = axl.TitForTat() tf = TransitiveFingerprint(strategy) tf.fingerprint(repetitions=1, progress_bar=False, processes=2) self.assertEqual(tf.data.shape, (50, 50))