from src.main import *
from src.utils.conversion import Conversion

cipher = {
    'A': '00',
    'C': '01',
    'G': '10',
    'T': '11',
    '00': 'A',
    '01': 'C',
    '10': 'G',
    '11': 'T'
}

conversion = Conversion()


def test_str_format():
    assert conversion.str_format("Hello world") == "STARTHelLo wOrldSTOP"
    assert conversion.str_format("This is a secret message") == "STARTThis IS#a&secrEt§meSsAgESTOP"


def test_str_to_binary():
    assert conversion.str_to_binary("HELLO WORLD !") == "01001000010001010100110001001100010011110010000001010111010011110101001001001100010001000010000000100001"
    assert conversion.str_to_binary("hi") == "0110100001101001"
    assert conversion.str_to_binary("START") == "0101001101010100010000010101001001010100"
    assert conversion.str_to_binary("STOP") == "01010011010101000100111101010000"
    assert conversion.str_to_binary("STARTThis IS#a&secrEt§meSsAgESTOP") == "010100110101010001000001010100100101010001010100011010000110100101110011001000000100100101010011001000110110000100100110011100110110010101100011011100100100010101110100101001110110110101100101010100110111001101000001011001110100010101010011010101000100111101010000"


def test_binary_to_dna():
    assert conversion.binary_to_dna("00110110") == "ATCG"
    assert conversion.binary_to_dna("0110100001101001") == "CGGACGGC"
    assert conversion.binary_to_dna("0101001101010100010000010101001001010100") == "CCATCCCACAACCCAGCCCA"
    assert conversion.binary_to_dna("01010011010101000100111101010000") == "CCATCCCACATTCCAA"
    assert conversion.binary_to_dna("010100110101010001000001010100100101010001010100011010000110100101110011001000000100100101010011001000110110000100100110011100110110010101100011011100100100010101110100101001110110110101100101010100110111001101000001011001110100010101010011010101000100111101010000") == "CCATCCCACAACCCAGCCCACCCACGGACGGCCTATAGAACAGCCCATAGATCGACAGCGCTATCGCCCGATCTAGCACCCTCAGGCTCGTCCGCCCCATCTATCAACCGCTCACCCCATCCCACATTCCAA"


def test_dna_to_binary():
    assert conversion.dna_to_binary("ATCG") == "00110110"
    assert conversion.dna_to_binary("CGGACGGC") == "0110100001101001"


def test_binary_to_str():
    assert conversion.binary_to_str("01001000010001010100110001001100010011110010000001010111010011110101001001001100010001000010000000100001") == "HELLO WORLD !"
    assert conversion.binary_to_str("0110100001101001") == "hi"

def test_str_reverse():
    assert conversion.str_reverse("STARTThis IS#a&secrEt§meSsAgESTOP") == "this is a secret message"


def test_str_to_dna():
    assert conversion.str_to_dna("This is a secret message!") == "CCATCCCACAACCCAGCCCACCCACGGACGGCCTATAGAACAGCCCATAGATCGACAGCGCTATCGCCCGATCTAGCACCCTCAGGCTCGTCCGCCCCATCTATCAACCGCTCACCAGACCCATCCCACATTCCAA"
    assert conversion.str_to_dna("hi") == "CCATCCCACAACCCAGCCCACGGACGGCCCATCCCACATTCCAA"


def test_dna_to_str():
    assert conversion.dna_to_str("CCATCCCACAACCCAGCCCACCCACGGACGGCCTATAGAACAGCCCATAGATCGACAGCGCTATCGCCCGATCTAGCACCCTCAGGCTCGTCCGCCCCATCTATCAACCGCTCACCAGACCCATCCCACATTCCAA") == "this is a secret message!"
    assert conversion.dna_to_str("CCATCCCACAACCCAGCCCACGGACGGCCCATCCCACATTCCAA") == "hi"