Browse Source

Simplify IccProfileId IsSet

af/merge-core
Jason Nelson 8 years ago
parent
commit
e40177004b
  1. 15
      src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs
  2. 32
      tests/ImageSharp.Tests/MetaData/Profiles/ICC/Various/IccProfileIdTests.cs

15
src/ImageSharp/MetaData/Profiles/ICC/Various/IccProfileId.cs

@ -13,7 +13,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// A profile ID with all values set to zero
/// </summary>
public static readonly IccProfileId Zero = new IccProfileId(0, 0, 0, 0);
public static readonly IccProfileId Zero = default;
/// <summary>
/// Initializes a new instance of the <see cref="IccProfileId"/> struct.
@ -53,16 +53,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// Gets a value indicating whether the ID is set or just consists of zeros
/// </summary>
public bool IsSet
{
get
{
return this.Part1 != 0
&& this.Part2 != 0
&& this.Part3 != 0
&& this.Part4 != 0;
}
}
public bool IsSet => !this.Equals(Zero);
/// <summary>
/// Compares two <see cref="IccProfileId"/> objects for equality.
@ -131,4 +122,4 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
return value.ToString("X").PadLeft(8, '0');
}
}
}
}

32
tests/ImageSharp.Tests/MetaData/Profiles/ICC/Various/IccProfileIdTests.cs

@ -0,0 +1,32 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.MetaData.Profiles.Icc;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Icc
{
public class IccProfileIdTests
{
[Fact]
public void ZeroIsEqualToDefault()
{
Assert.True(IccProfileId.Zero.Equals(default));
Assert.False(default(IccProfileId).IsSet);
}
[Fact]
public void SetIsTrueWhenNonDefaultValue()
{
var id = new IccProfileId(1, 2, 3, 4);
Assert.True(id.IsSet);
Assert.Equal(1u, id.Part1);
Assert.Equal(2u, id.Part2);
Assert.Equal(3u, id.Part3);
Assert.Equal(4u, id.Part4);
}
}
}
Loading…
Cancel
Save