public void SetData_with_null_argument_throws_exception()
    {
      // arrange
      FarbfeldImageData target;

      target = new FarbfeldImageData();

      // act & assert
      Assert.Throws<ArgumentNullException>(() => { target.SetData(null); });
    }
    public void Constructor_with_image_should_extract_data_properly()
    {
      // arrange
      FarbfeldImageData target;
      FarbfeldImageData expected;

      expected = FarbfeldDecoder.Decode(Path.Combine(this.DataPath, "polygon.png.ff"));

      // act
      using (Bitmap bitmap = (Bitmap)Image.FromFile(Path.Combine(this.DataPath, "polygon.png")))
      {
        target = new FarbfeldImageData(bitmap);
      }

      // assert
      // As .NET images used 0-255 for RGB colors, there might not be a direct match between
      // the uint16 and byte versions. So when we compare the colours, we'll discard one of the
      // bytes and compare only that
      this.AssertEqual(expected, target, true);
    }
    public void SetData_with_invalid_argument_throws_exception()
    {
      // arrange
      FarbfeldImageData target;
      Exception ex;
      string expectedMessage;

      target = new FarbfeldImageData
               {
                 Width = 32,
                 Height = 32
               };

      expectedMessage = "Data must contain 4096 elements.";

      // act
      ex = Assert.Throws<ArgumentException>(() => { target.SetData(new ushort[16]); });

      // assert
      Assert.AreEqual(expectedMessage, ex.Message);
    }
    protected void AssertEqual(FarbfeldImageData expected, FarbfeldImageData actual, bool fuzzyMatch)
    {
      ushort[] expectedData;
      ushort[] actualData;

      Assert.AreEqual(expected.Width, actual.Width);
      Assert.AreEqual(expected.Height, actual.Height);

      expectedData = expected.GetData();
      actualData = actual.GetData();

      Assert.AreEqual(expectedData.Length, actualData.Length);

      for (int i = 0; i < expectedData.Length; i++)
      {
        if (!fuzzyMatch)
        {
          Assert.AreEqual(expectedData[i], actualData[i]);
        }
        else
        {
          byte expectedByte;
          byte actualByte;

          expectedByte = (byte)(expectedData[i] >> 8);
          actualByte = (byte)(actualData[i] >> 8);

          Assert.AreEqual(expectedByte, actualByte);
        }
      }
    }