<commit_before>package au.edu.unimelb.boldapp;

import android.util.Log;
import java.io.File;
import java.io.StringWriter;
import java.util.Date;
import java.util.UUID;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;


public class FileIOTest extends TestCase {

	public void testGetAppRootPath() throws Exception {
		assertEquals(new File("/mnt/sdcard/bold"), FileIO.getAppRootPath());
	}

	public void testGetUsersPath() throws Exception {
		assertEquals(new File("/mnt/sdcard/bold/users"),
				FileIO.getUsersPath());
	}

	public void testGetImagesPath() throws Exception {
		assertEquals(new File("/mnt/sdcard/bold/images"),
				FileIO.getImagesPath());
	}

	public void testGetRecordingsPath() throws Exception {
		assertEquals(new File("/mnt/sdcard/bold/recordings"),
				FileIO.getRecordingsPath());
	}

	public void testWriteRead1() throws Exception {
		FileIO.write("testdir/test1/test1", "hallo");
		assertEquals("hallo", FileIO.read("/mnt/sdcard/bold/testdir/test1/test1"));
	}

	public void testWriteRead2() throws Exception {
		FileIO.write("/mnt/sdcard/bold/testdir/test1/", "okies");
		assertEquals("okies", FileIO.read("testdir/test1/"));
	}

	public void testWriteRead3() throws Exception {
		FileIO.write("testdir/test3", "once upon\n a time\n");
		assertEquals("once upon\n a time\n", FileIO.read("testdir/test3"));
	}

	public void testWriteRead4() throws Exception {
		FileIO.write("testdir/test4", "once upon\n a time");
		assertTrue(!"once upon\n a time\n"
				.equals(FileIO.read("testdir/test4")));
	}

	public void testWriteRead5() throws Exception {
		FileIO.write(
				new File(FileIO.getAppRootPath(), "testdir/test1/test1"),
				"hallo");
		assertEquals("hallo", FileIO.read(
				new File(FileIO.getAppRootPath(), "testdir/test1/test1")));
	}

	public void testWriteAndReadUsers() throws Exception {
		Language l1 = new Language("Alekano", "gah");
		List<Language> languages = new ArrayList<Language>();
		languages.add(l1);
		// Writes two users, and then reads them back.

		User user = new User(UUID.randomUUID(), "Test User", languages);
		FileIO.writeUser(user);

		User user2 = new User(UUID.randomUUID(), "Test Üser 2", languages);
		FileIO.writeUser(user2);

		// NOTE: ASSUMING readUsers() RETURNS THE LIST IN REVERSE CHRONOLOGICAL
		// ORDER
		List<User> users = FileIO.readUsers();

		Log.i("FileIOTest", user.getLanguages().get(0).getCode());
		Log.i("FileIOTest", users.get(1).getLanguages().get(0).getCode());

		assertEquals(user.getName(), users.get(1).getName());
		assertEquals(user.getUUID(), users.get(1).getUUID());
		assertEquals(user.getLanguages().get(0).getName(),
				users.get(1).getLanguages().get(0).getName());
		assertEquals(user.getLanguages().get(0).getCode(),
				users.get(1).getLanguages().get(0).getCode());
		assertEquals(user2.getName(), users.get(0).getName());
		assertEquals(user2.getUUID(), users.get(0).getUUID());
		assertEquals(user.getLanguages().get(0).getName(),
				users.get(0).getLanguages().get(0).getName());
		assertEquals(user.getLanguages().get(0).getCode(),
				users.get(0).getLanguages().get(0).getCode());


		// Cleanup these test user directories.
		FileUtils.deleteDirectory(new File(FileIO.getUsersPath(),
				user.getUUID().toString()));
		FileUtils.deleteDirectory(new File(FileIO.getUsersPath(),
				user2.getUUID().toString()));
	}

	public void testWriteAndReadRecording() throws Exception {
		Language language = new Language("English", "eng");
		Recording recording = new Recording(
				UUID.randomUUID(), UUID.randomUUID(), "FileIOTestRecording",
				new Date(), language);

		FileIO.writeRecording(recording);

		Recording readRecording = FileIO.readRecording(recording.getUUID());

		Log.i("FileIOTest", recording.getLanguage().toString());
		Log.i("FileIOTest", readRecording.getLanguage().toString());

		assertEquals(recording.getUUID(), readRecording.getUUID());
		assertEquals(recording.getCreatorUUID(),
				readRecording.getCreatorUUID());
		assertEquals(recording.getName(), readRecording.getName());
		assertEquals(recording.getDate(), readRecording.getDate());
		assertEquals(recording.getOriginalUUID(), readRecording.getOriginalUUID());<commit_msg>added note in FileIOTest to explain the creation of test users<commit_after>package au.edu.unimelb.boldapp;

import android.util.Log;
import java.io.File;
import java.io.StringWriter;
import java.util.Date;
import java.util.UUID;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;


public class FileIOTest extends TestCase {

	public void testGetAppRootPath() throws Exception {
		assertEquals(new File("/mnt/sdcard/bold"), FileIO.getAppRootPath());
	}

	public void testGetUsersPath() throws Exception {
		assertEquals(new File("/mnt/sdcard/bold/users"),
				FileIO.getUsersPath());
	}

	public void testGetImagesPath() throws Exception {
		assertEquals(new File("/mnt/sdcard/bold/images"),
				FileIO.getImagesPath());
	}

	public void testGetRecordingsPath() throws Exception {
		assertEquals(new File("/mnt/sdcard/bold/recordings"),
				FileIO.getRecordingsPath());
	}

	public void testWriteRead1() throws Exception {
		FileIO.write("testdir/test1/test1", "hallo");
		assertEquals("hallo", FileIO.read("/mnt/sdcard/bold/testdir/test1/test1"));
	}

	public void testWriteRead2() throws Exception {
		FileIO.write("/mnt/sdcard/bold/testdir/test1/", "okies");
		assertEquals("okies", FileIO.read("testdir/test1/"));
	}

	public void testWriteRead3() throws Exception {
		FileIO.write("testdir/test3", "once upon\n a time\n");
		assertEquals("once upon\n a time\n", FileIO.read("testdir/test3"));
	}

	public void testWriteRead4() throws Exception {
		FileIO.write("testdir/test4", "once upon\n a time");
		assertTrue(!"once upon\n a time\n"
				.equals(FileIO.read("testdir/test4")));
	}

	public void testWriteRead5() throws Exception {
		FileIO.write(
				new File(FileIO.getAppRootPath(), "testdir/test1/test1"),
				"hallo");
		assertEquals("hallo", FileIO.read(
				new File(FileIO.getAppRootPath(), "testdir/test1/test1")));
	}

	public void testWriteAndReadUsers() throws Exception {
		Language l1 = new Language("Alekano", "gah");
		List<Language> languages = new ArrayList<Language>();
		languages.add(l1);
		// Writes two users, and then reads them back.

		User user = new User(UUID.randomUUID(), "Test User", languages);
		FileIO.writeUser(user);

		User user2 = new User(UUID.randomUUID(), "Test Üser 2", languages);
		FileIO.writeUser(user2);

		// NOTE: ASSUMING readUsers() RETURNS THE LIST IN REVERSE CHRONOLOGICAL
		// ORDER.
		List<User> users = FileIO.readUsers();

		Log.i("FileIOTest", user.getLanguages().get(0).getCode());
		Log.i("FileIOTest", users.get(1).getLanguages().get(0).getCode());

		assertEquals(user.getName(), users.get(1).getName());
		assertEquals(user.getUUID(), users.get(1).getUUID());
		assertEquals(user.getLanguages().get(0).getName(),
				users.get(1).getLanguages().get(0).getName());
		assertEquals(user.getLanguages().get(0).getCode(),
				users.get(1).getLanguages().get(0).getCode());
		assertEquals(user2.getName(), users.get(0).getName());
		assertEquals(user2.getUUID(), users.get(0).getUUID());
		assertEquals(user.getLanguages().get(0).getName(),
				users.get(0).getLanguages().get(0).getName());
		assertEquals(user.getLanguages().get(0).getCode(),
				users.get(0).getLanguages().get(0).getCode());


		//If there are other users, this won't work.
		// Cleanup these test user directories.
		FileUtils.deleteDirectory(new File(FileIO.getUsersPath(),
				user.getUUID().toString()));
		FileUtils.deleteDirectory(new File(FileIO.getUsersPath(),
				user2.getUUID().toString()));
	}

	public void testWriteAndReadRecording() throws Exception {
		Language language = new Language("English", "eng");
		Recording recording = new Recording(
				UUID.randomUUID(), UUID.randomUUID(), "FileIOTestRecording",
				new Date(), language);

		FileIO.writeRecording(recording);

		Recording readRecording = FileIO.readRecording(recording.getUUID());

		Log.i("FileIOTest", recording.getLanguage().toString());
		Log.i("FileIOTest", readRecording.getLanguage().toString());

		assertEquals(recording.getUUID(), readRecording.getUUID());
		assertEquals(recording.getCreatorUUID(),
				readRecording.getCreatorUUID());
		assertEquals(recording.getName(), readRecording.getName());
		assertEquals(recording.getDate(), readRecording.getDate());
		assertEquals(recording.getOriginalUUID(), readRecording.getOriginalUUID());
{'fraction_non_alphanumeric': 0.1610645864402891, 'fraction_numerical': 0.010554089709762533, 'mean_word_length': 5.358862144420131, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3431890', 'n_tokens_mistral': 3004, 'n_tokens_neox': 2812, 'n_words': 509}