<commit_before># encoding: utf8
from __future__ import unicode_literals
import six
from decimal import Decimal
from unittest import TestCase
from ..currency import currencies, Currency
from ..amount import Amount, _ZeroAmount


class AmountTests(TestCase):

    def test_equality(self):
        self.assertEqual(
            Amount(currencies["GBP"], 132),
            Amount(currencies["GBP"], 132),
        )
        self.assertNotEqual(
            Amount(currencies["GBP"], 132),
            Amount(currencies["USD"], 132),
        )
        self.assertNotEqual(
            Amount(currencies["GBP"], 132),
            Amount(currencies["GBP"], 99),
        )
        self.assertNotEqual(
            Amount(currencies["GBP"], 132),
            object(),
        )

    def test_add(self):
        self.assertEqual(
            Amount(currencies["GBP"], 132) + Amount(currencies["GBP"], 100),
            Amount(currencies["GBP"], 232),
        )
        with self.assertRaises(ValueError):
            Amount(currencies["GBP"], 132) + Amount(currencies["USD"], 100)

    def test_subtract(self):
        self.assertEqual(
            Amount(currencies["GBP"], 132) - Amount(currencies["GBP"], 100),
            Amount(currencies["GBP"], 32),
        )
        with self.assertRaises(ValueError):
            Amount(currencies["GBP"], 132) - Amount(currencies["USD"], 100)

    def test_comparison(self):
        self.assertLess(
            Amount(currencies["GBP"], 10),
            Amount(currencies["GBP"], 20),
        )
        self.assertGreater(
            Amount(currencies["GBP"], 20),
            Amount(currencies["GBP"], 10),
        )
        self.assertLessEqual(
            Amount(currencies["GBP"], 20),
            Amount(currencies["GBP"], 20),
        )
        self.assertGreaterEqual(
            Amount(currencies["GBP"], 20),
            Amount(currencies["GBP"], 20),
        )

    def test_format(self):
        self.assertEqual(
            six.text_type(Amount(currencies["USD"], 132)),
            "1.32 USD",
        )
        self.assertEqual(
            six.text_type(Amount(currencies["USD"], -132)),
            "-1.32 USD",
        )
        self.assertEqual(
            six.text_type(Amount(
                Currency("GBP", "826", 2, 'Pound Sterling', prefix="£"),
                132,
            )),
            "£1.32",
        )

    def test_bool(self):
        self.assertTrue(Amount(currencies["USD"], 1))
        self.assertFalse(Amount(currencies["USD"], 0))
        self.assertTrue(Amount.from_code_and_major("USD", Decimal('0.01')))
        self.assertFalse(Amount.from_code_and_major("USD", Decimal('0.00')))

    def test_apply_factor(self):
        self.assertEqual(
            Amount(currencies["GBP"], 150).apply_factor(2),
            Amount(currencies["GBP"], 300),
        )
        self.assertEqual(
            Amount(currencies["GBP"], 100).apply_factor(Decimal("1.004")),
            Amount(currencies["GBP"], 100),
        )
        self.assertEqual(
            Amount(currencies["GBP"], 100).apply_factor(Decimal("1.005")),
            Amount(currencies["GBP"], 101),
        )
        with self.assertRaises(ValueError):
            Amount(currencies["GBP"], 100).apply_factor(1.005)

    def test_from_code_and_minor(self):
        self.assertEqual(
            Amount.from_code_and_minor("GBP", 300),
            Amount(currencies["GBP"], 300),
        )
        self.assertEqual(
            Amount.from_code_and_minor("gbp", 300),<commit_msg>Test that negative values evaluate to `True`<commit_after># encoding: utf8
from __future__ import unicode_literals
import six
from decimal import Decimal
from unittest import TestCase
from ..currency import currencies, Currency
from ..amount import Amount, _ZeroAmount


class AmountTests(TestCase):

    def test_equality(self):
        self.assertEqual(
            Amount(currencies["GBP"], 132),
            Amount(currencies["GBP"], 132),
        )
        self.assertNotEqual(
            Amount(currencies["GBP"], 132),
            Amount(currencies["USD"], 132),
        )
        self.assertNotEqual(
            Amount(currencies["GBP"], 132),
            Amount(currencies["GBP"], 99),
        )
        self.assertNotEqual(
            Amount(currencies["GBP"], 132),
            object(),
        )

    def test_add(self):
        self.assertEqual(
            Amount(currencies["GBP"], 132) + Amount(currencies["GBP"], 100),
            Amount(currencies["GBP"], 232),
        )
        with self.assertRaises(ValueError):
            Amount(currencies["GBP"], 132) + Amount(currencies["USD"], 100)

    def test_subtract(self):
        self.assertEqual(
            Amount(currencies["GBP"], 132) - Amount(currencies["GBP"], 100),
            Amount(currencies["GBP"], 32),
        )
        with self.assertRaises(ValueError):
            Amount(currencies["GBP"], 132) - Amount(currencies["USD"], 100)

    def test_comparison(self):
        self.assertLess(
            Amount(currencies["GBP"], 10),
            Amount(currencies["GBP"], 20),
        )
        self.assertGreater(
            Amount(currencies["GBP"], 20),
            Amount(currencies["GBP"], 10),
        )
        self.assertLessEqual(
            Amount(currencies["GBP"], 20),
            Amount(currencies["GBP"], 20),
        )
        self.assertGreaterEqual(
            Amount(currencies["GBP"], 20),
            Amount(currencies["GBP"], 20),
        )

    def test_format(self):
        self.assertEqual(
            six.text_type(Amount(currencies["USD"], 132)),
            "1.32 USD",
        )
        self.assertEqual(
            six.text_type(Amount(currencies["USD"], -132)),
            "-1.32 USD",
        )
        self.assertEqual(
            six.text_type(Amount(
                Currency("GBP", "826", 2, 'Pound Sterling', prefix="£"),
                132,
            )),
            "£1.32",
        )

    def test_bool(self):
        self.assertTrue(Amount(currencies["USD"], 1))
        self.assertTrue(Amount(currencies["USD"], -1))
        self.assertFalse(Amount(currencies["USD"], 0))
        self.assertTrue(Amount.from_code_and_major("USD", Decimal('0.01')))
        self.assertTrue(Amount.from_code_and_major("USD", Decimal('-0.01')))
        self.assertFalse(Amount.from_code_and_major("USD", Decimal('0.00')))

    def test_apply_factor(self):
        self.assertEqual(
            Amount(currencies["GBP"], 150).apply_factor(2),
            Amount(currencies["GBP"], 300),
        )
        self.assertEqual(
            Amount(currencies["GBP"], 100).apply_factor(Decimal("1.004")),
            Amount(currencies["GBP"], 100),
        )
        self.assertEqual(
            Amount(currencies["GBP"], 100).apply_factor(Decimal("1.005")),
            Amount(currencies["GBP"], 101),
        )
        with self.assertRaises(ValueError):
            Amount(currencies["GBP"], 100).apply_factor(1.005)

    def test_from_code_and_minor(self):
        self.assertEqual(
            Amount.from_code_and_minor("GBP", 300),
            Amount(currencies["GBP"], 300),
        )
        self.assertEqual(
            Amount.from_code_and_minor("gbp", 300),
{'fraction_non_alphanumeric': 0.14636855992223302, 'fraction_numerical': 0.03916122760727677, 'mean_word_length': 2.179690949227373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7292230', 'n_tokens_mistral': 2500, 'n_tokens_neox': 2075, 'n_words': 339}