using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using UnityEngine;

namespace Testing.Root
{
    // TODO Comment
    public abstract class Tests
    {
        public int assertionsRun;
        public int assertionsPassed;

        public void Assert(bool condition)
        {
            assertionsRun++;
            if (condition)
            {
                assertionsPassed++;
                return;
            }
            UnityEngine.Debug.LogError(GetType().Name + ", " + GetCallingMethod() + " failed.");
        }

        public void Assert(bool condition, string message)
        {
            assertionsRun++;
            if (condition)
            {
                assertionsPassed++;
                return;
            }
            UnityEngine.Debug.LogError(GetType().Name + ", " + GetCallingMethod() + " failed: " + message);
        }

        public void Assert(object a, object b, string message)
        {
            assertionsRun++;
            if (a.Equals(b))
            {
                assertionsPassed++;
                return;
            }
            UnityEngine.Debug.LogError(GetType().Name + ", " + GetCallingMethod() + " failed, " + a + " != " + b + ": " + message);
        }

        public string GetAssertionStatus()
        {
            return this.assertionsPassed + "/" + this.assertionsRun;
        }

        private string GetCallingMethod()
        {
            StackTrace st = new StackTrace();
            StackFrame sf = st.GetFrame(2);

            return sf.GetMethod().Name;
        }
    }
}
