// Arup Guha
// 10/26/26
// Use of HashSet for COP 3330.

import java.util.*;

public class TestHashSet {

	public static void main(String[] args) {
		randomTest();
	}

	public static void hardCodedTest() {
	
		// Add some stuff to the set.
		HashSet<String> set = new HashSet<String>();
		set.add("apple");
		set.add("banana");
		set.add("apple");
		
		// Test size.
		System.out.println(set.size());
		
		// How to iterate through all the items in the set.
		for (String fruit: set)
			System.out.println(fruit);
		
		// Check if orange is in the set, if not, add it!
		if (!set.contains("orange")) {
			System.out.println("There was no orange in the set, but I'll add one.");
			set.add("orange");
		}
		
		// How to iterate through all the items in the set.
		for (String fruit: set)
			System.out.println(fruit);
		
		// Try to remove dragonfruit.
		boolean flag = set.remove("dragonfruit");
		
		// Output result of attempted removal.
		if (flag)
			System.out.println("We removed the dragonfruit.");
		else
			System.out.println("Your set never contained a dragondruit.");
		
		// Remove orange.
		set.remove("orange");
		System.out.println("just removed the oragne");
		for (String fruit: set)
			System.out.println(fruit);
		
		// This is a test to see that the two separate string objects that
		// s1 and s2 reference are treated as identical objects in the eyes
		// of the set.
		String s1 = "kiwi";
		String s2 = ("KIWI").toLowerCase();
		set.add(s1);
		set.add(s2);
		for (String fruit: set)
			System.out.println(fruit);
		
	}
	
	public static void randomTest() {
		
		Random rndObj = new Random();
		
		int i = 0;
		HashSet<Integer> mine = new HashSet<Integer>();
		
		// I simulate collecting baseball cards randomly until I get all 1000 cards
		// in a set.
		while (mine.size() < 1000) {
			
			// Just to see our progress after every 1000 cards.
			if (i%1000 == 0 && i > 0)
				System.out.println(i+" "+mine.size());
			
			// Add a randomly generated card to our set.
			int x = rndObj.nextInt(1000);
			mine.add(x);
			i++;
		}
			
		// See how long it took!
		System.out.println("Took "+i+" turns to get all 1000 objects.");
	}
}