示例#1
0
        public async Task CHI3()
        {
            string testName = "CHI3";

            //Arrange
            HttpClient client = _factory.CreateClient();

            ChiSquaredAndFishersExactTestModel model = new ChiSquaredAndFishersExactTestModel();

            model.DatasetID          = _factory.SheetNames.Single(x => x.Value == "Chi-sq and Fishers Exact").Key;
            model.Response           = "TreatmentH";
            model.GroupingFactor     = "Treatmenty";
            model.ResponseCategories = "Treatment x";
            model.ChiSquaredTest     = true;
            model.FishersExactTest   = true;
            model.BarnardsTest       = true;
            model.Hypothesis         = "Two-sided";

            //Act
            HttpResponseMessage response = await client.PostAsync("Analyses/ChiSquaredAndFishersExactTest", new FormUrlEncodedContent(model.ToKeyValue()));

            IEnumerable <string> errors = await Helpers.ExtractErrors(response);

            //Assert
            Assert.Contains("The Response categories (Treatment x) contains missing data where there are observations present in the Response. Please check the input data and make sure the data was entered correctly.", errors);
            Helpers.SaveOutput("ChiSquaredAndFishersExactTest", testName, errors);
        }
示例#2
0
        public async Task CHI24()
        {
            string testName = "CHI24";

            //Arrange
            HttpClient client = _factory.CreateClient();

            ChiSquaredAndFishersExactTestModel model = new ChiSquaredAndFishersExactTestModel();

            model.DatasetID          = _factory.SheetNames.Single(x => x.Value == "Chi-sq and Fishers Exact").Key;
            model.Response           = "CountEF";
            model.GroupingFactor     = "Bin(E";
            model.ResponseCategories = "Bin(F";
            model.ChiSquaredTest     = true;
            model.FishersExactTest   = true;
            model.BarnardsTest       = true;
            model.Hypothesis         = "Greater-than";

            //Act
            StatsOutput statsOutput = await Helpers.SubmitAnalysis(client, "ChiSquaredAndFishersExactTest", new FormUrlEncodedContent(model.ToKeyValue()));

            Helpers.SaveTestOutput("ChiSquaredAndFishersExactTest", model, testName, statsOutput);

            //Assert
            string expectedHtml = File.ReadAllText(Path.Combine("ExpectedResults", "ChiSquaredAndFishersExactTest", testName + ".html"));

            Assert.Equal(Helpers.RemoveAllImageNodes(expectedHtml), Helpers.RemoveAllImageNodes(statsOutput.HtmlResults));
        }
示例#3
0
        public async Task CHI4()
        {
            string testName = "CHI4";

            //Arrange
            HttpClient client = _factory.CreateClient();

            ChiSquaredAndFishersExactTestModel model = new ChiSquaredAndFishersExactTestModel();

            model.DatasetID          = _factory.SheetNames.Single(x => x.Value == "Chi-sq and Fishers Exact").Key;
            model.Response           = "Count_2";
            model.GroupingFactor     = "Treatmenty";
            model.ResponseCategories = "TreatmentG";
            model.ChiSquaredTest     = true;
            model.FishersExactTest   = true;
            model.BarnardsTest       = true;
            model.Hypothesis         = "Two-sided";

            //Act
            HttpResponseMessage response = await client.PostAsync("Analyses/ChiSquaredAndFishersExactTest", new FormUrlEncodedContent(model.ToKeyValue()));

            IEnumerable <string> warnings = await Helpers.ExtractWarnings(response);

            //Assert
            Assert.Contains("The Response (Count_2) contains missing data. Any rows of the dataset that contain missing responses will be excluded prior to the analysis.", warnings);
            Helpers.SaveOutput("ChiSquaredAndFishersExactTest", testName, warnings);
        }
示例#4
0
        public void GetCommandLineArguments_ReturnsCorrectString()
        {
            //Arrange
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            ChiSquaredAndFishersExactTestModel sut = GetModel(GetDataset());

            //Act
            string result = sut.GetCommandLineArguments();

            //Assert
            Assert.Equal("Count Group Respcat Y Y Two-sided N 0.05", result);
        }
示例#5
0
        public void ScriptFileName_ReturnsCorrectString()
        {
            //Arrange
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            ChiSquaredAndFishersExactTestModel sut = new ChiSquaredAndFishersExactTestModel();

            //Act
            string result = sut.ScriptFileName;

            //Assert
            Assert.Equal("ChiSquaredAndFishersExactTest", result);
        }
示例#6
0
        public void LoadArguments_ReturnsCorrectArguments()
        {
            //Arrange
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            ChiSquaredAndFishersExactTestModel sut = new ChiSquaredAndFishersExactTestModel(GetDataset());

            List <Argument> arguments = new List <Argument>();

            arguments.Add(new Argument {
                Name = "BarnardsTest", Value = "False"
            });
            arguments.Add(new Argument {
                Name = "ChiSquaredTest", Value = "True"
            });
            arguments.Add(new Argument {
                Name = "FishersExactTest", Value = "True"
            });
            arguments.Add(new Argument {
                Name = "GroupingFactor", Value = "Group"
            });
            arguments.Add(new Argument {
                Name = "Hypothesis", Value = "Two-sided"
            });
            arguments.Add(new Argument {
                Name = "Response", Value = "Count"
            });
            arguments.Add(new Argument {
                Name = "ResponseCategories", Value = "Respcat"
            });
            arguments.Add(new Argument {
                Name = "Significance", Value = "0.05"
            });

            Assert.Equal(8, arguments.Count);

            //Act
            sut.LoadArguments(arguments);

            //Assert
            Assert.False(sut.BarnardsTest);
            Assert.True(sut.ChiSquaredTest);
            Assert.True(sut.FishersExactTest);
            Assert.Equal("Group", sut.GroupingFactor);
            Assert.Equal("Two-sided", sut.Hypothesis);
            Assert.Equal("Count", sut.Response);
            Assert.Equal("Respcat", sut.ResponseCategories);
            Assert.Equal("0.05", sut.Significance);
        }
示例#7
0
        public void HypothesesList_ReturnsCorrectList()
        {
            //Arrange
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            ChiSquaredAndFishersExactTestModel sut = new ChiSquaredAndFishersExactTestModel();

            //Act
            IEnumerable <string> result = sut.HypothesesList;

            //Assert
            Assert.IsAssignableFrom <IEnumerable <string> >(result);
            Assert.Equal(new List <string>()
            {
                "Two-sided", "Less-than", "Greater-than"
            }, result);
        }
示例#8
0
        public void SignificancesList_ReturnsCorrectList()
        {
            //Arrange
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            ChiSquaredAndFishersExactTestModel sut = new ChiSquaredAndFishersExactTestModel();

            //Act
            IEnumerable <string> result = sut.SignificancesList;

            //Assert
            Assert.IsAssignableFrom <IEnumerable <string> >(result);
            Assert.Equal(new List <string>()
            {
                "0.1", "0.05", "0.01", "0.001"
            }, result);
        }
示例#9
0
        private ChiSquaredAndFishersExactTestModel GetModel(IDataset dataset)
        {
            var model = new ChiSquaredAndFishersExactTestModel(dataset)
            {
                BarnardsTest       = false,
                ChiSquaredTest     = true,
                FishersExactTest   = true,
                GroupingFactor     = "Group",
                Hypothesis         = "Two-sided",
                Response           = "Count",
                ResponseCategories = "Respcat",
                Significance       = "0.05"
            };

            return(model);
        }
示例#10
0
        public void ExportData_ReturnsCorrectStringArray()
        {
            //Arrange
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            Mock <IDataset> mockDataset = new Mock <IDataset>();

            mockDataset.Setup(x => x.DatasetID).Returns(It.IsAny <int>);
            mockDataset.Setup(x => x.DatasetToDataTable()).Returns(GetTestDataTable());

            ChiSquaredAndFishersExactTestModel sut = GetModel(mockDataset.Object);

            //Act
            string[] result = sut.ExportData();

            //Assert
            Assert.Equal("Count,Group,Respcat", result[0]);
            Assert.Equal(9, result.Count()); //as blank responses are removed
            Assert.StartsWith("6,a_Tr,N", result[3]);
        }
示例#11
0
        public void GetArguments_ReturnsCorrectArguments()
        {
            //Arrange
            System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            ChiSquaredAndFishersExactTestModel sut = GetModel(GetDataset());

            //Act
            List <Argument> result = sut.GetArguments().ToList();

            //Assert
            var barnardsTest = result.Single(x => x.Name == "BarnardsTest");

            Assert.Equal("False", barnardsTest.Value);

            var chiSquaredTest = result.Single(x => x.Name == "ChiSquaredTest");

            Assert.Equal("True", chiSquaredTest.Value);

            var fishersExactTest = result.Single(x => x.Name == "FishersExactTest");

            Assert.Equal("True", fishersExactTest.Value);

            var groupingFactor = result.Single(x => x.Name == "GroupingFactor");

            Assert.Equal("Group", groupingFactor.Value);

            var hypothesis = result.Single(x => x.Name == "Hypothesis");

            Assert.Equal("Two-sided", hypothesis.Value);

            var response = result.Single(x => x.Name == "Response");

            Assert.Equal("Count", response.Value);

            var responseCategories = result.Single(x => x.Name == "ResponseCategories");

            Assert.Equal("Respcat", responseCategories.Value);

            var significance = result.Single(x => x.Name == "Significance");

            Assert.Equal("0.05", significance.Value);
        }
示例#12
0
        public async Task CHI27()
        {
            string testName = "CHI27";

            //Arrange
            HttpClient client = _factory.CreateClient();

            ChiSquaredAndFishersExactTestModel model = new ChiSquaredAndFishersExactTestModel();

            model.DatasetID          = _factory.SheetNames.Single(x => x.Value == "Chi-sq and Fishers Exact").Key;
            model.Response           = "CountGH";
            model.GroupingFactor     = "TreatmentG";
            model.ResponseCategories = "TreatmentH";
            model.ChiSquaredTest     = true;
            model.FishersExactTest   = true;
            model.BarnardsTest       = true;
            model.Hypothesis         = "Greater-than";

            //Act
            HttpResponseMessage response = await client.PostAsync("Analyses/ChiSquaredAndFishersExactTest", new FormUrlEncodedContent(model.ToKeyValue()));

            IEnumerable <string> warnings = await Helpers.ExtractWarnings(response);

            //Assert
            Assert.Contains("Grouping factor or the Response categories have more than two levels. Barnard&#x27;s test can only be performed when there are two levels of the Grouping factor and two Response categories.", warnings);
            Helpers.SaveOutput("ChiSquaredAndFishersExactTest", testName, warnings);

            //Act - ignore warnings
            model.BarnardsTest = true; //Deselecting Barnards test!
            var modelIgnoreWarnings = model.ToKeyValue();

            modelIgnoreWarnings.Add("ignoreWarnings", "true");
            StatsOutput statsOutput = await Helpers.SubmitAnalysis(client, "ChiSquaredAndFishersExactTest", new FormUrlEncodedContent(modelIgnoreWarnings));

            Helpers.SaveTestOutput("ChiSquaredAndFishersExactTest", model, testName, statsOutput);

            //Assert
            string expectedHtml = File.ReadAllText(Path.Combine("ExpectedResults", "ChiSquaredAndFishersExactTest", testName + ".html"));

            Assert.Equal(Helpers.RemoveAllImageNodes(expectedHtml), Helpers.RemoveAllImageNodes(statsOutput.HtmlResults));
        }
 public async Task <IActionResult> ChiSquaredAndFishersExactTest(ChiSquaredAndFishersExactTestModel model, bool ignoreWarnings)
 {
     return(await RunAnalysis(model, ignoreWarnings));
 }
 public ChiSquaredAndFishersExactTestValidator(ChiSquaredAndFishersExactTestModel csfet)
     : base(csfet.DataTable)
 {
     csfetVariables = csfet;
 }