/// <summary> /// Necessary so that the gameObject can be exposed to the radiation. /// Performs all the needed steps for calculating and recieving the radiation. /// </summary> private void GetAndApplyDose() { if (RaySource.Instance == null) { return; } // update vertices controller.UpdateVertices(RaySource.Instance.transform.position); controller.SortOutUnhittedVertices(RaySource.Instance.RayTracer); // get doses float[] distances = RaySource.Instance.RayTracer.GetDistances(controller.GetRelevantVerticePositions()); float[] addedDoses = DoseCalculator.Calculate(distances, RaySource.Instance.BaseEnergy, Time.fixedDeltaTime); // store doses controller.StoreDoses(addedDoses); // calculate colors and avg. dose float[] accumulatedDoses = controller.VerticeData.Select(x => x.Dose).ToArray(); float avgDose = DoseCalculator.GetAVGDose(accumulatedDoses); Color32[] colors = ColorCalculator.Calculate(accumulatedDoses); // appy colors and avg. dose container.ApplyColors(colors); DoseInfo.Instance.Controller.SetAVGDose(avgDose); }
public IEnumerator AVGIsZeroWhenSourceShouldBeActive_Test() { // setup float expected = 0f; IInputWrapper input = Substitute.For <IInputWrapper>(); input.GetKeyDown(KeyCode.Space).Returns(true); SetPrivateField(UnityInput.Instance, "input", input); // till start is called yield return(new WaitForEndOfFrame()); // till update is called yield return(new WaitForEndOfFrame()); // perform input.GetKeyDown(KeyCode.Space).Returns(false); yield return(new WaitForSeconds(1f)); // get controller = GetPrivateField <MeshController, RayReciever>(reciever, "controller"); float[] doses = controller.VerticeData.Select(x => x.Dose).ToArray(); float actual = DoseCalculator.GetAVGDose(doses); // assert Assert.AreEqual(expected, actual); }
public void GetAVGDoseReturnsCorrectDose_Test(float[] doses, float expected) { // perform float actual = DoseCalculator.GetAVGDose(doses); // assert Assert.AreEqual(expected, actual); }
public IEnumerator AVGIsZeroWhenSourceIsNotActive_Test() { // setup float expected = 0f; // wait till start is called yield return(new WaitForEndOfFrame()); // wait till first update is called yield return(new WaitForEndOfFrame()); // perform yield return(new WaitForSeconds(1f)); // get controller = GetPrivateField <MeshController, RayReciever>(reciever, "controller"); float[] doses = controller.VerticeData.Select(x => x.Dose).ToArray(); float actual = DoseCalculator.GetAVGDose(doses); // assert Assert.AreEqual(expected, actual); }