/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import junit.framework.Assert;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import tools.mips.Memory;

/**
 *
 * @author EUGENIO CARVALHO
 */
public class MemoryJUnitTest {

    private Memory memory;

    public MemoryJUnitTest() {

    }

    @BeforeClass
    public static void setUpClass() {

    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
        memory = new Memory(16 * 1024);
    }

    @After
    public void tearDown() {
    }

    @Test
    public void WriteBinaryByte() throws Exception {
//        System.out.println(Long.toBinaryString(2L));
//        System.out.println(Long.toBinaryString(2L));
        Long value = -3L;
        memory.W(0L, Long.toBinaryString(value), 4);
        Assert.assertEquals(value, memory.ReadLong(0L, 4));

        value = 3L;
        memory.W(0L, Long.toBinaryString(value), 4);
        Assert.assertEquals(value, memory.ReadLong(0L, 4));

//        System.out.println(Long.toBinaryString(-3L));
//        System.out.println(Long.parseUnsignedLong(Long.toBinaryString(-3L), 2));
//        System.out.println(Long.parseUnsignedLong("11111111111111111111111111111101", 2));
//        System.out.println(Long.parseUnsignedLong("1111111111111111111111111111111111111111111111111111111111111101", 2));
    }

//    @Test
//    public void WriteByte() throws Exception {
//        String bd = "00000010";
//        memory.WB(bd);
//        Assert.assertEquals(bd, memory.RB(0));
//    }
//
//    @Test
//    public void WriteByteAddressed() throws Exception {
//        String bd = "00000010";
//        Long address = 16L;
//        memory.WB(address, bd);
//        Assert.assertEquals(bd, memory.RB(address));
//    }
//    @Test
//    public void WriteMultByteAddressed() throws Exception {
//        Long value = 14030L;
//
//        Long address = 16L;
//        // Escreve 4 bytes a partir do endereco 16
//        memory.W(address, Long.toBinaryString(value), 4);
//
//        // Lê 4 bytes a partir do endereco 16 -> converte binario para long
//        Assert.assertEquals(value, memory.ReadLong(address, 4));
//    }
//
//    @Test
//    public void WriteNegativeValueAddressed() throws Exception {
//        Long value = -3L;
//        Long address = 16L;
//        // Escreve 4 bytes a partir do endereco 16
//        memory.W(address, value, 4);
//        // Lê 4 bytes a partir do endereco 16 -> converte binario para long
//        Assert.assertEquals(value, memory.ReadLong(address, 4));
//    }
//    @Test
//    public void WriteInvalidAddress() throws Exception {
//        boolean result = false;
//        try {
//            String bd = "00000010";
//            Long address = 17000L;
//            memory.WB(address, bd);
//        } catch (Exception e) {
//            result = true;
//        }
//        Assert.assertTrue(result);
//    }
}
