<commit_before>﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static Blaze.Propositions.Formula;

namespace UnitTest.Propositions
{
    [TestClass]
    public class FormulaValueTest
    {
        [TestMethod]
        public void TruthValue_Constant()
        {
            Assert.AreEqual(true, True.TruthValue);
            Assert.AreEqual(false, False.TruthValue);

            var p = Variable("P");
            Assert.AreEqual(null, (p & True).TruthValue);
            Assert.AreEqual(true, (p | True).TruthValue);
            Assert.AreEqual(false, (p & False).TruthValue);
            Assert.AreEqual(null, (p | False).TruthValue);
        }

        [TestMethod]
        public void TruthValue_Negation()
        {
            var p = Variable("P");
            var _p = !p;

            Assert.AreEqual(null, _p.TruthValue);
            p.Value = false;
            Assert.AreEqual(true, _p.TruthValue);
            p.Value = true;
            Assert.AreEqual(false, _p.TruthValue);
        }

        [TestMethod]
        public void TruthValue_And()
        {
            var p = Variable("P");
            var q = Variable("Q");
            var p_q = p & q;

            Assert.AreEqual(null, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(false, p_q.TruthValue);
            q.Value = true;
            Assert.AreEqual(null, p_q.TruthValue);

            p.Value = false;
            q.Value = false;
            Assert.AreEqual(false, p_q.TruthValue);
            q.Value = true;
            Assert.AreEqual(false, p_q.TruthValue);

            p.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);
        }

        [TestMethod]
        public void TruthValue_Or()
        {
            var p = Variable("P");
            var q = Variable("Q");
            var p_q = p | q;

            Assert.AreEqual(null, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(null, p_q.TruthValue);
            q.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);

            p.Value = false;
            q.Value = false;
            Assert.AreEqual(false, p_q.TruthValue);
            q.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);

            p.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);
        }

        [TestMethod]
        public void TruthValue_Implication()
        {
            var p = Variable("P");
            var q = Variable("Q");
            var p_q = Imply(p, q);

            p.Value = true;
            q.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(false, p_q.TruthValue);

            p.Value = false;
            q.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(true, p_q.TruthValue);
        }

        [TestMethod]
        public void TruthValue_Equivalence()
        {
            var p = Variable("P");
            var q = Variable("Q");
            var p_q = Equivalent(p, q);

            p.Value = true;
            q.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(false, p_q.TruthValue);

            p.Value = false;
            q.Value = true;
            Assert.AreEqual(false, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(true, p_q.TruthValue);
        }

        [TestMethod]
        public void TruthValue_Xor()
        {
            var p = Variable("P");
            var q = Variable("Q");
            var p_q = p ^ q;

            p.Value = true;
            q.Value = true;
            Assert.AreEqual(false, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(true, p_q.TruthValue);

            p.Value = false;
            q.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(false, p_q.TruthValue);
        }
    }
}<commit_msg>Refactor<commit_after>﻿using System;
using Blaze.Propositions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using static Blaze.Propositions.Formula;

namespace UnitTest.Propositions
{
    [TestClass]
    public class FormulaValueTest
    {
        VariableFormula p;
        VariableFormula q;

        [TestInitialize]
        public void Initialize()
        {
            p = Variable("P");
            q = Variable("Q");
        }

        [TestMethod]
        public void TruthValue_Constant()
        {
            Assert.AreEqual(true, True.TruthValue);
            Assert.AreEqual(false, False.TruthValue);

            Assert.AreEqual(null, (p & True).TruthValue);
            Assert.AreEqual(true, (p | True).TruthValue);
            Assert.AreEqual(false, (p & False).TruthValue);
            Assert.AreEqual(null, (p | False).TruthValue);
        }

        [TestMethod]
        public void TruthValue_Negation()
        {
            var _p = !p;

            Assert.AreEqual(null, _p.TruthValue);
            p.Value = false;
            Assert.AreEqual(true, _p.TruthValue);
            p.Value = true;
            Assert.AreEqual(false, _p.TruthValue);
        }

        [TestMethod]
        public void TruthValue_And()
        {
            var p_q = p & q;

            Assert.AreEqual(null, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(false, p_q.TruthValue);
            q.Value = true;
            Assert.AreEqual(null, p_q.TruthValue);

            p.Value = false;
            q.Value = false;
            Assert.AreEqual(false, p_q.TruthValue);
            q.Value = true;
            Assert.AreEqual(false, p_q.TruthValue);

            p.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);
        }

        [TestMethod]
        public void TruthValue_Or()
        {
            var p_q = p | q;

            Assert.AreEqual(null, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(null, p_q.TruthValue);
            q.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);

            p.Value = false;
            q.Value = false;
            Assert.AreEqual(false, p_q.TruthValue);
            q.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);

            p.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);
        }

        [TestMethod]
        public void TruthValue_Implication()
        {
            var p_q = Imply(p, q);

            p.Value = true;
            q.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(false, p_q.TruthValue);

            p.Value = false;
            q.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(true, p_q.TruthValue);
        }

        [TestMethod]
        public void TruthValue_Equivalence()
        {
            var p_q = Equivalent(p, q);

            p.Value = true;
            q.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(false, p_q.TruthValue);

            p.Value = false;
            q.Value = true;
            Assert.AreEqual(false, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(true, p_q.TruthValue);
        }

        [TestMethod]
        public void TruthValue_Xor()
        {
            var p_q = p ^ q;

            p.Value = true;
            q.Value = true;
            Assert.AreEqual(false, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(true, p_q.TruthValue);

            p.Value = false;
            q.Value = true;
            Assert.AreEqual(true, p_q.TruthValue);
            q.Value = false;
            Assert.AreEqual(false, p_q.TruthValue);
        }
    }
}
{'fraction_non_alphanumeric': 0.10992058489852514, 'fraction_numerical': 0.0, 'mean_word_length': 1.4487654320987655, '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': '1781606', 'n_tokens_mistral': 2439, 'n_tokens_neox': 2371, 'n_words': 446}