func TestContactsSwap(t *testing.T) { contact0 := kademlia.NewContact(kademlia.NewRandomNodeID(), "") contact1 := kademlia.NewContact(kademlia.NewRandomNodeID(), "") contacts := kademlia.Contacts{contact0, contact1} // swap once contacts.Swap(0, 1) if contact1 != contacts[0] || contact0 != contacts[1] { t.Error("Contacts were not swapped properly") } // return to original ordering contacts.Swap(0, 1) if contact0 != contacts[0] || contact1 != contacts[1] { t.Error("Contacts were not swapped properly") } }