-
-
Notifications
You must be signed in to change notification settings - Fork 427
perf: use index access to Dictionary #1621
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
235ba2c
218c44c
8df77a1
7a1ddd3
104d59f
4e3cf39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using ImageMagick; | ||
using Xunit; | ||
|
||
namespace Magick.NET.Tests; | ||
|
||
public partial class MomentsTests | ||
{ | ||
public class TheGetChannelMethod | ||
{ | ||
[Fact] | ||
public void ShouldReturnNullWhenChannelDoesNotExist() | ||
{ | ||
using var image = new MagickImage(Files.ImageMagickJPG); | ||
var moments = image.Moments(); | ||
|
||
Assert.NotNull(moments.GetChannel(PixelChannel.Red)); | ||
Assert.NotNull(moments.GetChannel(PixelChannel.Green)); | ||
Assert.NotNull(moments.GetChannel(PixelChannel.Blue)); | ||
|
||
Assert.Null(moments.GetChannel(PixelChannel.Black)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using ImageMagick; | ||
using Xunit; | ||
|
||
namespace Magick.NET.Tests; | ||
|
||
public partial class PerceptualHashTests | ||
{ | ||
public class TheGetChannelMethod | ||
{ | ||
[Fact] | ||
public void ShouldReturnNullWhenChannelDoesNotExist() | ||
{ | ||
var hash = new PerceptualHash("81b4488652898d48a7a9622346206e620f8a646682939835e986ec98c78f887ae8c67f81b1e884c58a0d18af2d622718fd35623ffdeac9a78cbaedaa81d888434e824c683ad781c37895978c8688c426628ed61b216279b81b48887318a1628af43622a2619d162372"); | ||
|
||
Assert.NotNull(hash.GetChannel(PixelChannel.Red)); | ||
Assert.NotNull(hash.GetChannel(PixelChannel.Green)); | ||
Assert.NotNull(hash.GetChannel(PixelChannel.Blue)); | ||
|
||
Assert.Null(hash.GetChannel(PixelChannel.Black)); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,38 @@ | ||
// Copyright Dirk Lemstra https://github.com/dlemstra/Magick.NET. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using System; | ||
using ImageMagick; | ||
using Xunit; | ||
|
||
namespace Magick.NET.Tests; | ||
|
||
public partial class PerceptualHashTests | ||
{ | ||
public class TestPerceptualHash : IPerceptualHash | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will move this to a separate file after merging this PR. Not yet sure where I want to put this. And maybe we could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm used to anonymous object that can implements an Interface in PHP or Kotlin 😜 I don't know |
||
{ | ||
public IChannelPerceptualHash GetChannel(PixelChannel channel) | ||
=> null; | ||
|
||
public double SumSquaredDistance(IPerceptualHash other) | ||
{ | ||
throw new System.NotImplementedException(); | ||
} | ||
} | ||
|
||
public class TheSumSquaredDistanceMethod | ||
{ | ||
[Fact] | ||
public void ShouldThrowNotSupportedExceptionIfCustomImplementationDoesNotHaveExpectedChannels() | ||
{ | ||
using var image = new MagickImage(Files.ImageMagickJPG); | ||
var phash = image.PerceptualHash(); | ||
Assert.NotNull(phash); | ||
|
||
var exception = Assert.Throws<NotSupportedException>(() => phash.SumSquaredDistance(new TestPerceptualHash())); | ||
Assert.Equal("other IPerceptualHash must have Red, Green and Blue channel", exception.Message); | ||
} | ||
|
||
[Fact] | ||
public void ShouldReturnTheDifference() | ||
{ | ||
|
Uh oh!
There was an error while loading. Please reload this page.