package ch.zhaw.ads;

import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.*;
import java.util.*;
import java.io.*;

public class RankingTreeServerTest {

    BinaryTreeRankingServer binaryTreeRankingServer;
    RankingTreeServer rankingTreeServer;
    String csv;

    @Before
    public void setUp() throws Exception {
        binaryTreeRankingServer = new BinaryTreeRankingServer();
        rankingTreeServer = new RankingTreeServer();
        csv = openFile("./build/resources/main/RangZuerich.csv");
    }

    @Test
    public void test1() throws Exception {
        rankingTreeServer.execute(csv);
        binaryTreeRankingServer.execute(csv);

        System.out.println(rankingTreeServer.getTree().height());
        System.out.println(binaryTreeRankingServer.getTree().height());
        // The AVL tree constantly rebalances itself when new items are inserted, therefore its height remains rather small the whole time. On the other hand, the unbalanced sorted binary tree does not do any rebalancing, leading to it growing in height.
    }

    // helper functions
    private String openFile(String name) throws Exception {
		BufferedReader br = new BufferedReader(
				new InputStreamReader(new FileInputStream(name), "ISO-8859-1"));
		StringBuffer b = new StringBuffer();
		String line;
		while ((line = br.readLine()) != null) {
			b.append(line);
			b.append('\n');
		}
		return b.toString();
    }
}

