Lookup() public static method

public static Lookup ( String animal ) : string
animal String
return string
Example #1
0
        public static void Main()
        {
            var dictionary = new Dictionary<string, int>
            {
                {"one", 1},
                {"two", 4},
                {"three", 9},
                {"four", 16}
            };

            var result1 =
                from x in dictionary.Lookup("two")
                from y in ToStringIfLessThenTen(x)
                select y;

            var result2 =
                from x in dictionary.Lookup("four")
                from y in ToStringIfLessThenTen(x)
                select y;

            var result3 =
                from x in dictionary.Lookup("five")
                from y in ToStringIfLessThenTen(x)
                select y;

            PrintMaybe(result1);
            PrintMaybe(result2);
            PrintMaybe(result3);

            PrintResult(result1.OrElse("some default value"));
            PrintResult(result2.OrElse("some default value"));
            PrintResult(result3.OrElse("some default value"));
        }
Example #2
0
 public void MaybeTest()
 {
     var dict = new Dictionary<int, int>();
     dict[0] = 1;
     dict[2] = 3;
     Assert.IsTrue(dict.Lookup(0).HasValue);
     Assert.IsFalse(dict.Lookup(1).HasValue);
     Assert.AreEqual(dict.Lookup(1).GetOrElse(8), 8);
     Assert.AreEqual(dict.Lookup(2).Map(x => x + 1).GetOrElse(0), 4);
 }
Example #3
0
        public void Lookup_NonExistantKeyReturnsNull()
        {
            // Arrange
            var dictionary = new Dictionary<InstructionType, Action<ExecutionContext, Instruction>>();

            // Act
            var value = dictionary.Lookup(InstructionType.Call);

            // Assert
            value.Should().BeNull();
        }
        public void LookupWhenFound()
        {
            var dict =
                new Dictionary<int, string>
                {
                    [1] = "A",
                    [2] = "B"
                };

            Assert.AreEqual("B", dict.Lookup(2).Value);
        }
Example #5
0
        public void Lookup_ReturnsValueForExistingKey()
        {
            // Arrange
            Action<ExecutionContext, Instruction> action = (e, i) => { /* Do nothing */ };
            var dictionary = new Dictionary<InstructionType, Action<ExecutionContext, Instruction>>
            {
                { InstructionType.Mult, action }
            };

            // Act
            var value = dictionary.Lookup(InstructionType.Mult);

            // Assert
            value.Should().Be(action);
        }
Example #6
0
        public void Reload()
        {
            var homeDir = Environment.GetEnvironmentVariable("HOMEDRIVE") + Environment.GetEnvironmentVariable("HOMEPATH");

            Dictionary<string, string> ini;
            try {
                ini = ReadIniFile(Path.Combine(homeDir, ".souse"));
            } catch (IOException) {
                ini = new Dictionary<string, string>();
            }

            AudioRate = ini.Lookup("audio-in-sample-rate").Select(int.Parse).OrElse(44100);
            AudioBits = ini.Lookup("audio-in-bits").Select(int.Parse).OrElse(16);
            AudioChannels = ini.Lookup("audio-in-channels").Select(int.Parse).OrElse(1);
            AudioBufferSize = ini.Lookup("audio-in-buffer-size").Select(int.Parse).OrElse(6144);
            AudioBufferCount = ini.Lookup("audio-in-buffer-count").Select(int.Parse).OrElse(4);
            AnalysisHighPassFreq = ini.Lookup("analysis-high-pass-frequency").Select(int.Parse).OrElse(1000);
            AnalysisLowPassFreq = ini.Lookup("analysis-low-pass-frequency").Select(int.Parse).OrElse(20000);
            AnalysisTotalSensitivity = ini.Lookup("analysis-total-sensitivity").Select(double.Parse).OrElse(0.015);
            AnalysisBucketSensitivity = ini.Lookup("analysis-bucket-sensitivity").Select(double.Parse).OrElse(0.015);
            AnalysisA440 = ini.Lookup("analysis-a440").Select(double.Parse).OrElse(440);
            RPCBindPrefix = ini.Lookup("rpc-bind-prefix").OrElse((string) null);
        }
        public void LookupWhenNotFound()
        {
            var dict = new Dictionary<int, string>();

            Assert.IsFalse(dict.Lookup(2).HasValue);
        }
Example #8
0
        static void ProcessTestResult(TestResult testResult, Dictionary<string, ReferenceData> referenceActionLogs)
        {
            Log.Info("Processing test result: {0}", testResult.Name);

            foreach (var testResultActionLog in testResult.ActionLogs)
            {
                Log.Info("Processing test result action log: {0}", testResultActionLog.ActionLogName);
                var referenceDataActionLog = referenceActionLogs
                    .Lookup(testResultActionLog.ActionLogName)
                    ;

                if (referenceDataActionLog == null)
                {
                    Log.Warning("No matching reference action log found: {0}", testResultActionLog.ActionLogName);
                    continue;
                }

                try
                {
                    ProcessActionLog(referenceDataActionLog, testResult, testResultActionLog);
                }
                catch (ExitCodeException)
                {
                    throw;
                }
                catch (Exception exc)
                {
                    Log.Warning("Error while processing result action log: {0}", exc.Message);
                }
            }
        }