# -*- coding: utf-8 -*-

import pytest

import copy
import datetime
import dingguo
import os
import yaml

def test_sum_init_eur():
    assert dingguo.Sum(1.23, u'EUR') == dingguo.Sum(1.23, u'€')

def test_sum_init_usd():
    assert dingguo.Sum(1.23, u'USD') == dingguo.Sum(1.23, u'US$')

def test_distance_metres():
    assert int(dingguo.Distance(1.23, u'km').metres) == 1230

def test_person_first_name():
    p = dingguo.Person()
    p.first_name = u'äbc'
    assert p.first_name == u'äbc'
    p.first_name = u'qrßtuvw'
    assert p.first_name == u'qrßtuvw'

def test_person_first_name_string():
    p = dingguo.Person()
    with pytest.raises(Exception):
        p.first_name = 'äbc'

def test_person_last_name():
    p = dingguo.Person()
    p.last_name = u'歌曲'
    assert p.last_name == u'歌曲'
    p.last_name = u'bär'
    assert p.last_name == u'bär'

def test_person_last_name_string():
    p = dingguo.Person()
    with pytest.raises(Exception):
        p.last_name = 'äbc'

@pytest.mark.parametrize(('text', 'sum'), [
    [u'$1.23 USD',  dingguo.Sum(1.23, u'USD')],
    [u'$30 USD',    dingguo.Sum(30.0, u'USD')],
    [u'$30.00 USD', dingguo.Sum(30.0, u'USD')],
    [u'$8',         dingguo.Sum(8.0,  u'USD')],
    [u'$8.00',      dingguo.Sum(8.0,  u'USD')],
    ])
def test_sum_parse_text(text, sum):
    assert dingguo.Sum.parse_text(text) == sum

@pytest.mark.parametrize(('text'), [
    u'pre$1.23 USD',
    u'$1.23 USDpost',
    ])
def test_sum_parse_text_fail(text):
    with pytest.raises(Exception):
        dingguo.Sum.parse_text(text)

@pytest.mark.parametrize(('minuend', 'subtrahend', 'difference'), [
    [dingguo.Sum(5.0, u'USD'), dingguo.Sum(2.0, u'USD'), dingguo.Sum(3.0, u'USD')],
    [dingguo.ScalarFigure(5.0, u'cm'), dingguo.ScalarFigure(2.0, u'cm'), dingguo.ScalarFigure(3.0, u'cm')],
    [dingguo.ScalarFigure(1.0, u'kg'), dingguo.ScalarFigure(2.0, u'kg'), dingguo.ScalarFigure(-1.0, u'kg')],
    ])
def test_figure_sub(minuend, subtrahend, difference):
    minuend_copy = copy.deepcopy(minuend)
    subtrahend_copy = copy.deepcopy(subtrahend)
    assert (minuend - subtrahend) == difference
    assert minuend_copy == minuend
    assert subtrahend_copy == subtrahend

@pytest.mark.parametrize(('minuend', 'subtrahend'), [
    [dingguo.Sum(5.0, u'USD'), dingguo.Sum(2.0, u'EUR')],
    [dingguo.ScalarFigure(5.0, u'cm'), dingguo.ScalarFigure(2.0, u'kg')],
    ])
def test_figure_sub_fail(minuend, subtrahend):
    with pytest.raises(Exception):
        (minuend - subtrahend)