<commit_before>package bakatxt.test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.LinkedList;

import org.junit.Before;
import org.junit.Test;

import bakatxt.core.BakaParser;
import bakatxt.core.Database;
import bakatxt.core.Task;
import bakatxt.core.UserInput;

public class UserInputTest {

    private Task dummy;
    private BakaParser _parser;
    private Database _database;

    @Before
    public void setUp() throws Exception {
        _parser = new BakaParser();
        _database = Database.getInstance();
    }

    @Test
    public void testAdd() {
        dummy = _parser.add("add testAdd command ");
        UserInput command = new UserInput("add", dummy);

        command.execute();
        LinkedList<Task> tasks = _database.getAllTasks();
        assertTrue(tasks.contains(dummy));

        command.undo();
        tasks = _database.getAllTasks();
        assertFalse(tasks.contains(dummy));
    }

    @Test
    public void testDelete() {
        dummy = _parser.add("add testDelete command tonight");
        UserInput command = new UserInput("delete", dummy);

        command.execute();
        LinkedList<Task> tasks = _database.getAllTasks();
        assertFalse(tasks.contains(dummy));

        command.undo();
        tasks = _database.getAllTasks();
        assertTrue(tasks.contains(dummy));
    }

    @Test
    public void testEdit() {
        dummy = _parser.add("add editing1");
        Task edit = _parser.add("add editing2");
        UserInput command = new UserInput("edit", dummy, edit);

        command.execute();
        LinkedList<Task> tasks = _database.getAllTasks();
        assertFalse(tasks.contains(dummy));

        command.undo();
        tasks = _database.getAllTasks();
        assertTrue(tasks.contains(dummy));
    }

    @Test
    public void testDone() {
        dummy = _parser.add("add done 1pm tomorrow");
        // _database.add(dummy);
        UserInput command = new UserInput("done", dummy, true);

        command.execute();
        LinkedList<Task> tasks = _database.getAllUndoneTasks();
        assertFalse(tasks.contains(dummy));

        command.undo();
        tasks = _database.getAllUndoneTasks();
        // assertTrue(tasks.contains(dummy));
    }
}<commit_msg>Close _database after each test case<commit_after>package bakatxt.test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.LinkedList;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import bakatxt.core.BakaParser;
import bakatxt.core.Database;
import bakatxt.core.Task;
import bakatxt.core.UserInput;

public class UserInputTest {

    private Task dummy;
    private BakaParser _parser;
    private Database _database;

    @Before
    public void setUp() throws Exception {
        _parser = new BakaParser();
        _database = Database.getInstance();
    }

    @After
    public void tearDown() throws Exception {
        _database.close();
    }

    @Test
    public void testAdd() {
        dummy = _parser.add("add testAdd command ");
        UserInput command = new UserInput("add", dummy);

        command.execute();
        LinkedList<Task> tasks = _database.getAllTasks();
        assertTrue(tasks.contains(dummy));

        command.undo();
        tasks = _database.getAllTasks();
        assertFalse(tasks.contains(dummy));
    }

    @Test
    public void testDelete() {
        dummy = _parser.add("add testDelete command tonight");
        UserInput command = new UserInput("delete", dummy);

        command.execute();
        LinkedList<Task> tasks = _database.getAllTasks();
        assertFalse(tasks.contains(dummy));

        command.undo();
        tasks = _database.getAllTasks();
        assertTrue(tasks.contains(dummy));
    }

    @Test
    public void testEdit() {
        dummy = _parser.add("add editing1");
        Task edit = _parser.add("add editing2");
        UserInput command = new UserInput("edit", dummy, edit);

        command.execute();
        LinkedList<Task> tasks = _database.getAllTasks();
        assertFalse(tasks.contains(dummy));

        command.undo();
        tasks = _database.getAllTasks();
        assertTrue(tasks.contains(dummy));
    }

    @Test
    public void testDone() {
        dummy = _parser.add("add done 1pm tomorrow");
        // _database.add(dummy);
        UserInput command = new UserInput("done", dummy, true);

        command.execute();
        LinkedList<Task> tasks = _database.getAllUndoneTasks();
        assertFalse(tasks.contains(dummy));

        command.undo();
        tasks = _database.getAllUndoneTasks();
        assertTrue(tasks.contains(dummy));
    }
}
{'fraction_non_alphanumeric': 0.1180452718426063, 'fraction_numerical': 0.0012693039983075946, 'mean_word_length': 2.7643312101910826, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '6183570', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1294, 'n_words': 296}