 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kodestruct.Tests.Common;
using Kodestruct.Concrete.ACI318_14;
using Kodestruct.Concrete.ACI.Entities;
using Kodestruct.Concrete.ACI;
using Kodestruct.Concrete.ACI318_14.Materials;
using Xunit;

namespace Kodestruct.Concrete.ACI318_14.Tests
{
     
    public partial class AciTensionDevelopmentTests : ToleranceTestBase
    {

        double tolerance; 

        public AciTensionDevelopmentTests()
        {

            tolerance = 0.02; //2% can differ from rounding
        }
        //PCA Notes on ACI 318-08
        //Example 4.1Development of Bars in Tension

        //Lightweight concrete
        //2.5 in. clear cover to stirrups
        //Epoxy-coated bars
        //fc' = 4000 psi
        //fy = 60,000 psi
        // Nominal diameter of No. 9 bar = 1.128 in.
        // Clear spacing between spliced bars 21.7 in.

        [Fact]
        public void GetTensionDevelopmentLength_PCAExample_4_1_Case1_ReturnsValue()
        {
            double RebarDiam = 1.1280;
            bool IsTopRebar = true;
            bool IsEpoxyCoated = true;
           ConcreteTypeByWeight type = ConcreteTypeByWeight.Lightweight;
            double ClearSpacing = 21.7;
            double ClearCover = 3.0;
            double fc = 4000;
            double ExcessRebarRatio = 1.0;
            DevelopmentTension tensDev = this.CreateDevelopmentObject(fc, RebarDiam, IsEpoxyCoated, type,
                0.0, ClearSpacing, ClearCover, IsTopRebar, ExcessRebarRatio, true);
            double ld = Math.Round(tensDev.GetTensionDevelopmentLength(true), 1);
            Assert.Equal(121.3, ld);
        }

        [Fact]
        public void GetTensionDevelopmentLength_PCAExample_4_1_Case2_ReturnsValue()
        {
            double RebarDiam = 1.1280;
            bool IsTopRebar = true;
            bool IsEpoxyCoated = true;
            ConcreteTypeByWeight type = ConcreteTypeByWeight.Lightweight;
            double ClearSpacing = 21.7;
            double ClearCover = 3.0;
            double fc = 4000;
            double ExcessRebarRatio = 1.0;
            DevelopmentTension tensDev = this.CreateDevelopmentObject(fc, RebarDiam, IsEpoxyCoated, type,
                0.0, ClearSpacing, ClearCover, IsTopRebar, ExcessRebarRatio, true);
            double ld = Math.Round(tensDev.GetTensionDevelopmentLength(100, 10, 2), 1);
            Assert.Equal(72.8, ld);
        }

        [Fact]
        public void GetTensionDevelopmentLength_PCAExample_4_2_ReturnsValue()
        {
            //need to find way to add sand light weight
        }

        //  No. 8 bars fc' = 4000 psi (normalweight concrete) and
        //  fy = 60,000 psi, and uncoated bars. Stirrups provided satisfy the minimum code requirements for beam shear
        //  reinforcement.
        [Fact]
        public void GetTensionDevelopmentLength_PCAExample_4_3_Case1_ReturnsValue()
        {
            double RebarDiam = 1.0;
            bool IsTopRebar = true;
            bool IsEpoxyCoated = false;
            ConcreteTypeByWeight type = ConcreteTypeByWeight.Normalweight;
            double ClearSpacing = 1.33;
            double ClearCover = 2.0;
            double fc = 4000;
            double ExcessRebarRatio = 1.0;
            DevelopmentTension tensDev = this.CreateDevelopmentObject(fc, RebarDiam, IsEpoxyCoated, type,
                0.0, ClearSpacing, ClearCover, IsTopRebar, ExcessRebarRatio, true);
            double ld = Math.Round(tensDev.GetTensionDevelopmentLength(true), 1);
            Assert.Equal(61.7, ld);
        }
        [Fact]
        public void GetTensionDevelopmentLength_PCAExample_4_3_Case2_ReturnsValue()
        {
            double RebarDiam = 1.0;
            bool IsTopRebar = true;
            bool IsEpoxyCoated = false;
            ConcreteTypeByWeight type = ConcreteTypeByWeight.Normalweight;
            double ClearSpacing = 1.33;
            double ClearCover = 2.0;
            double fc = 4000;
            double ExcessRebarRatio = 1.0;
            DevelopmentTension tensDev = this.CreateDevelopmentObject(fc, RebarDiam, IsEpoxyCoated, type,
                0.0, ClearSpacing, ClearCover, IsTopRebar, ExcessRebarRatio, true);
            double ld = Math.Round(tensDev.GetTensionDevelopmentLength(0.4, 10, 2), 0);


            Assert.Equal(47.0, ld);
        }
        [Fact]
        public void GetTensionDevelopmentLength_Basic()
        {
            double RebarDiam = 0.5;
            bool IsTopRebar = false;
            bool IsEpoxyCoated = false;
            ConcreteTypeByWeight type = ConcreteTypeByWeight.Normalweight;
            double fc = 4000;
            double ExcessRebarRatio = 1.0;
            IConcreteMaterial concrete = new ConcreteMaterial(fc, ConcreteTypeByWeight.Normalweight, null);
            Rebar rebar = new Rebar(RebarDiam,IsEpoxyCoated, new MaterialAstmA615(A615Grade.Grade60));
            bool MeetsRebarSpacingAndEdgeDistance = true;
            DevelopmentTension d = new DevelopmentTension(concrete, rebar, MeetsRebarSpacingAndEdgeDistance, IsTopRebar, ExcessRebarRatio, true, null);
            bool HasMinimumTransverseReinforcement = true;
            double l_d = d.GetTensionDevelopmentLength(HasMinimumTransverseReinforcement);

            double refValue = 18.97;
            double actualTolerance = EvaluateActualTolerance(l_d, refValue);

             Assert.True(actualTolerance<=tolerance);

        }

    }
}
