示例#1
0
        public void LongestCommonSubsequenceTest_Empty()
        {
            actual   = LCSLine.LCS(strEmpty, strEmpty);
            expected = strEmpty;
            Assert.AreEqual(expected, actual);

            actual   = LCSLine.LCS(strEmpty, str1);
            expected = strEmpty;
            Assert.AreEqual(expected, actual);

            actual   = LCSLine.LCS(str2, strEmpty);
            expected = strEmpty;
            Assert.AreEqual(expected, actual);

            actual   = LCSLine.LCS("ABC", "EFG");
            expected = strEmpty;
            Assert.AreEqual(expected, actual);
        }
示例#2
0
 public void LongestCommonSubsequenceTest_Normal()
 {
     actual   = LCSLine.LCS(str1, str2);
     expected = str3;
     Assert.AreEqual(expected, actual);
 }
示例#3
0
        static void Main(string[] args)
        {
            String filePath = "test.txt";

            if (args != null && args.Length != 0)
            {
                filePath = args[0];
            }
            StreamReader inputStreamReader = null;
            String       readLine;
            int          count = 0;

            String[] words;
            String   outputLine;

            try
            {
                inputStreamReader = new StreamReader(@filePath);

                // read each line of file
                while ((readLine = inputStreamReader.ReadLine()) != null)
                {
                    count++;

                    // for empty line
                    if (readLine == "")
                    {
                        continue;
                    }

                    words = readLine.Split(';');

                    // if there is not two words in a line
                    if (words.Length != 2)
                    {
                        Console.WriteLine("[ERROR]No only two words in the line {0}", count);
                        continue;
                    }

                    outputLine = LCSLine.LCS(words[0], words[1]).Trim();
                    System.Console.WriteLine(outputLine);
                }
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine("File not found.");
            }
            catch (IOException e)
            {
                // Extract some information from this exception, and then
                if (e.Source != null)
                {
                    Console.WriteLine("IOException source: {0}.", e.Source);
                }
                else
                {
                    Console.WriteLine("IOException happened.");
                }
            }
            finally
            {
                inputStreamReader.Close();
            }
        }