public void Merge_Many_Many() {
     StringWriter writer = new StringWriter();
     ParallelMergeSort p = new ParallelMergeSort( writer );
     double[] actual = p.Merge( new double[] { 1d, 2d, 3d, 4d }, new double[] { 1d, 2d, 3d, 4d } );
     double[] expected = new double[] { 1d, 1d, 2d, 2d, 3d, 3d, 4d, 4d };
     CollectionAssert.AreEqual( expected, actual );
 }
 public void Merge_Empty_One() {
     StringWriter writer = new StringWriter();
     ParallelMergeSort p = new ParallelMergeSort( writer );
     double[] actual = p.Merge( new double[] { }, new double[] { 1d } );
     double[] expected = new double[] { 1d };
     CollectionAssert.AreEqual( expected, actual );
 }
 public void MergeWrite_One_Empty() {
     StringWriter writer = new StringWriter();
     ParallelMergeSort p = new ParallelMergeSort( writer );
     p.MergeWrite( new double[] { 1d }, new double[] { } );
     string expected = "1" + Environment.NewLine;
     Assert.AreEqual( expected, writer.ToString() );
 }
 public void MergeWrite_Empty_Empty() {
     StringWriter writer = new StringWriter();
     ParallelMergeSort p = new ParallelMergeSort( writer );
     p.MergeWrite( new double[] { }, new double[] { } );
     string expected = "";
     Assert.AreEqual( expected, writer.ToString() );
 }
 public void AddBlock_One_Write() {
     StringWriter writer = new StringWriter();
     ParallelMergeSort p = new ParallelMergeSort( writer );
     p.AddBlock( new double[] { 1d, 5d, 3d, 4d }, true );
     string expected = "1" + Environment.NewLine +
                         "3" + Environment.NewLine +
                         "4" + Environment.NewLine +
                         "5" + Environment.NewLine;
     Assert.AreEqual( expected, writer.ToString() );
 }
 public void MergeWrite_Many_One() {
     StringWriter writer = new StringWriter();
     ParallelMergeSort p = new ParallelMergeSort( writer );
     p.MergeWrite( new double[] { 1d, 2d, 3d, 4d }, new double[] { 1d } );
     string expected =   "1" + Environment.NewLine +
                         "1" + Environment.NewLine +
                         "2" + Environment.NewLine +
                         "3" + Environment.NewLine +
                         "4" + Environment.NewLine;
     Assert.AreEqual( expected, writer.ToString() );
 }
 public void AddBlock_One_NoWrite() {
     StringWriter writer = new StringWriter();
     ParallelMergeSort p = new ParallelMergeSort( writer );
     p.AddBlock( new double[] { 1d, 5d, 3d, 4d } );
     Task.WaitAll( p.tasks.ToArray() );
     double[] expected = new double[] { 1d, 3d, 4d, 5d };
     double[] actual;
     if( p.SortedBlocks.TryDequeue( out actual ) )
         CollectionAssert.AreEqual( expected, actual );
     else
         Assert.Fail( "Could not dequeue" );
 }
 public void AddBlock_Five_Write() {
     StringWriter writer = new StringWriter();
     ParallelMergeSort p = new ParallelMergeSort( writer );
     p.AddBlock( new double[] { 4d, 3d, 2d, 1d } );
     p.AddBlock( new double[] { 8d, 7d, 6d, 5d } );
     p.AddBlock( new double[] { 12d, 11d, 10d, 9d } );
     p.AddBlock( new double[] { 16d, 15d, 14d, 13d } );
     p.AddBlock( new double[] { 20d, 19d, 18d, 17d }, true );
     string expected = "1" + Environment.NewLine +
                         "2" + Environment.NewLine +
                         "3" + Environment.NewLine +
                         "4" + Environment.NewLine +
                         "5" + Environment.NewLine +
                         "6" + Environment.NewLine +
                         "7" + Environment.NewLine +
                         "8" + Environment.NewLine +
                         "9" + Environment.NewLine +
                         "10" + Environment.NewLine +
                         "11" + Environment.NewLine +
                         "12" + Environment.NewLine +
                         "13" + Environment.NewLine +
                         "14" + Environment.NewLine +
                         "15" + Environment.NewLine +
                         "16" + Environment.NewLine +
                         "17" + Environment.NewLine +
                         "18" + Environment.NewLine +
                         "19" + Environment.NewLine +
                         "20" + Environment.NewLine;
     Assert.AreEqual( expected, writer.ToString() );
 }
		/// <summary>
		/// Po kontrole vsech argumentu nastava zpracovani vstupu
		/// </summary>
		/// <param name="reader"></param>
		/// <param name="writer"></param>
		internal static void ProcessFile(TextReader reader, TextWriter writer)
		{
			string line;
			List<double> dataBlock = new List<double>( BlockSize );
			ParallelMergeSort ps = new ParallelMergeSort( writer );

			while( ( line = reader.ReadLine() ) != null )
			{
				double value;
				if( !double.TryParse( line, out value ) )
					throw new FormatException();

				dataBlock.Add( value );

				if( reader.Peek() == -1 )
				{
					ps.AddBlock( dataBlock.ToArray(), true );
					dataBlock.Clear();
				}
				else if( dataBlock.Count == BlockSize )
				{
					ps.AddBlock( dataBlock.ToArray() );
					dataBlock.Clear();
				}
			}
			Task.WaitAll();
		}