From d524a1e17c41c9ca8261dcce43c338264b05d4e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20W=C3=B3jcik?= Date: Thu, 29 Aug 2024 22:02:12 +0200 Subject: [PATCH] code style preferences, EnforceCodeStyleInBuild, GenerateDocumentationFile, embedded DebugType, --- .editorconfig | 34 ++- Directory.Build.props | 1 + src/Roaring.Net/CRoaring/BulkContext.cs | 6 +- .../CRoaring/BulkContextInternal.cs | 6 +- .../CRoaring/FrozenRoaring32Bitmap.cs | 77 ++++--- .../CRoaring/IReadOnlyRoaring32Bitmap.cs | 28 +-- src/Roaring.Net/CRoaring/NativeMethods.cs | 72 +++--- src/Roaring.Net/CRoaring/Roaring32Bitmap.cs | 116 +++++----- .../CRoaring/Roaring32BitmapMemory.cs | 52 ++--- .../CRoaring/Roaring32Enumerator.cs | 4 +- src/Roaring.Net/CRoaring/Statistics.cs | 4 +- src/Roaring.Net/Roaring.Net.csproj | 2 + .../CRoaring/BulkContextTests/DisposeTests.cs | 14 +- .../ConvertTests.cs | 40 ++-- .../DisposeTests.cs | 44 ++-- .../FrozenRoaring32BitmapTestObject.cs | 4 +- .../FrozenRoaring32BitmapTestObjectFactory.cs | 4 +- .../CRoaring/IRoaring32BitmapTestObject.cs | 3 +- .../InlineMatrixTestObjectAttribute.cs | 24 +- .../CRoaring/InlineTestObjectAttribute.cs | 8 +- .../DisposeTests.cs | 42 ++-- .../FrozenBitmapTests.cs | 28 +-- .../Roaring32BitmapMemoryTests/WriteTests.cs | 84 +++---- .../Roaring32BitmapTestObjectFactoryBase.cs | 4 +- .../CRoaring/Roaring32BitmapTests/AddTests.cs | 186 +++++++-------- .../CRoaring/Roaring32BitmapTests/AndTests.cs | 143 ++++++------ .../Roaring32BitmapTests/CollectionTests.cs | 58 ++--- .../Roaring32BitmapTests/CompareTests.cs | 212 +++++++++--------- .../Roaring32BitmapTests/ContainsTests.cs | 42 ++-- .../Roaring32BitmapTests/CountTests.cs | 40 ++-- .../Roaring32BitmapTests/DisposeTests.cs | 9 +- .../Roaring32BitmapTests/EnumerableTests.cs | 50 ++--- .../Roaring32BitmapTests/IndexTests.cs | 26 +-- .../InitializationTests.cs | 81 +++---- .../Roaring32BitmapTests/MaintenanceTests.cs | 130 +++++------ .../Roaring32BitmapTests/MetricsTests.cs | 24 +- .../CRoaring/Roaring32BitmapTests/NotTests.cs | 86 +++---- .../CRoaring/Roaring32BitmapTests/OrTests.cs | 179 +++++++-------- .../Roaring32BitmapTests/RemoveTests.cs | 27 +-- .../Roaring32BitmapTestObject.cs | 4 +- .../Roaring32BitmapTestObjectFactory.cs | 2 +- .../SerializationTests.cs | 93 ++++---- .../Roaring32BitmapTests/StatisticsTests.cs | 100 ++++----- .../CRoaring/Roaring32BitmapTests/XorTests.cs | 157 ++++++------- .../Roaring32EnumeratorTests/DisposeTests.cs | 10 +- .../TestData/SerializationTestBitmap.cs | 21 +- 46 files changed, 1210 insertions(+), 1171 deletions(-) diff --git a/.editorconfig b/.editorconfig index 748de1d..9de33f9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,14 +1,42 @@ -# Code files -[*.{cs}] +root = true + +[*.cs] + +# Organize usings +dotnet_sort_system_directives_first = true +dotnet_separate_import_directive_groups = false + # Simplify name (IDE0001) dotnet_diagnostic.IDE0001.severity = warning # 'var' preferences (IDE0007 and IDE0008) dotnet_diagnostic.IDE0008.severity = warning +csharp_style_var_elsewhere = false:warning +csharp_style_var_for_built_in_types = true:warning +csharp_style_var_when_type_is_apparent = true:warning + +# Add braces (IDE0011) +dotnet_diagnostic.IDE0011.severity = warning + +# Add accessibility modifiers (IDE0040) +dotnet_diagnostic.IDE0040.severity = warning + +# Formatting rule (IDE0055) +dotnet_diagnostic.IDE0055.severity = warning + +# Use simple 'using' statement (IDE0063) +dotnet_diagnostic.IDE0063.severity = warning # Simplify new expression (IDE0090) dotnet_diagnostic.IDE0090.severity = warning +# Namespace declaration preferences (IDE0160 and IDE0161) +dotnet_diagnostic.IDE0161.severity = warning +csharp_style_namespace_declarations = file_scoped:warning + # Use LibraryImportAttribute instead of DllImportAttribute to generate p/invoke marshalling code at compile time. (SYSLIB1054) -dotnet_diagnostic.SYSLIB1054.severity = warning \ No newline at end of file +dotnet_diagnostic.SYSLIB1054.severity = warning + +# Missing XML comment for publicly visible type or member 'Type_or_Member' +dotnet_diagnostic.CS1591.severity = suggestion \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index 491916d..e420e0d 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -2,6 +2,7 @@ enable Nullable + true diff --git a/src/Roaring.Net/CRoaring/BulkContext.cs b/src/Roaring.Net/CRoaring/BulkContext.cs index ef6c1d9..a82bd58 100644 --- a/src/Roaring.Net/CRoaring/BulkContext.cs +++ b/src/Roaring.Net/CRoaring/BulkContext.cs @@ -7,7 +7,7 @@ namespace Roaring.Net.CRoaring; public sealed unsafe class BulkContext : IDisposable { internal Roaring32BitmapBase Bitmap { get; } - + internal readonly IntPtr Pointer; private bool _isDisposed; @@ -28,9 +28,9 @@ private void Dispose(bool disposing) { return; } - + Marshal.FreeHGlobal(Pointer); - + _isDisposed = true; } diff --git a/src/Roaring.Net/CRoaring/BulkContextInternal.cs b/src/Roaring.Net/CRoaring/BulkContextInternal.cs index 25e428f..a739cbd 100644 --- a/src/Roaring.Net/CRoaring/BulkContextInternal.cs +++ b/src/Roaring.Net/CRoaring/BulkContextInternal.cs @@ -7,10 +7,10 @@ namespace Roaring.Net.CRoaring; internal struct BulkContextInternal { public readonly IntPtr container; - + public readonly int idx; - + public readonly ushort key; - + public readonly byte typecode; } \ No newline at end of file diff --git a/src/Roaring.Net/CRoaring/FrozenRoaring32Bitmap.cs b/src/Roaring.Net/CRoaring/FrozenRoaring32Bitmap.cs index c8b421e..91c3743 100644 --- a/src/Roaring.Net/CRoaring/FrozenRoaring32Bitmap.cs +++ b/src/Roaring.Net/CRoaring/FrozenRoaring32Bitmap.cs @@ -1,14 +1,12 @@ using System; using System.Collections.Generic; -using System.Drawing; -using System.Runtime.InteropServices; namespace Roaring.Net.CRoaring; public unsafe class FrozenRoaring32Bitmap : Roaring32BitmapBase, IReadOnlyRoaring32Bitmap { internal Roaring32BitmapMemory Memory { get; } - + private readonly Roaring32Bitmap _bitmap; private bool _isDisposed; @@ -19,89 +17,90 @@ public unsafe class FrozenRoaring32Bitmap : Roaring32BitmapBase, IReadOnlyRoarin internal FrozenRoaring32Bitmap(Roaring32Bitmap bitmap) { - var size = bitmap.GetSerializationBytes(SerializationFormat.Frozen); + nuint size = bitmap.GetSerializationBytes(SerializationFormat.Frozen); Memory = new Roaring32BitmapMemory(size); _bitmap = bitmap.GetFrozenView(size, Memory.MemoryPtr); - + Pointer = _bitmap.Pointer; } - + internal FrozenRoaring32Bitmap(IntPtr pointer, Roaring32BitmapMemory memory) { Pointer = pointer; Memory = memory; - + _bitmap = new Roaring32Bitmap(pointer); } - + protected override void Dispose(bool disposing) { if (_isDisposed) { return; } - + _bitmap.Dispose(); Memory.Release(this); - + _isDisposed = true; } ~FrozenRoaring32Bitmap() => Dispose(false); - + public bool Contains(uint value) => _bitmap.Contains(value); - + public bool ContainsBulk(BulkContext context, uint value) { if (context.Bitmap != this) { throw new ArgumentException(ExceptionMessages.BulkContextBelongsToOtherBitmap, nameof(context)); } - + return NativeMethods.roaring_bitmap_contains_bulk(Pointer, context.Pointer, value); } public bool ContainsRange(uint start, uint end) => _bitmap.ContainsRange(start, end); - + public bool ValueEquals(Roaring32BitmapBase? bitmap) => _bitmap.ValueEquals(bitmap); - + public bool IsSubsetOf(Roaring32BitmapBase? bitmap) => _bitmap.IsSubsetOf(bitmap); public bool IsProperSubsetOf(Roaring32BitmapBase? bitmap) => _bitmap.IsProperSubsetOf(bitmap); - + public bool IsSupersetOf(Roaring32BitmapBase? bitmap) => _bitmap.IsSupersetOf(bitmap); - - public bool IsProperSupersetOf(Roaring32BitmapBase? bitmap) => _bitmap.IsProperSupersetOf(bitmap); - + + public bool IsProperSupersetOf(Roaring32BitmapBase? bitmap) => _bitmap.IsProperSupersetOf(bitmap); + public bool TryGetValue(uint index, out uint value) => _bitmap.TryGetValue(index, out value); + public long GetIndex(uint value) => _bitmap.GetIndex(value); - + public ulong CountLessOrEqualTo(uint value) => _bitmap.CountLessOrEqualTo(value); - + public ulong[] CountManyLessOrEqualTo(uint[] values) => _bitmap.CountManyLessOrEqualTo(values); public ulong CountRange(uint start, uint end) => _bitmap.CountRange(start, end); public Roaring32Bitmap Not() => _bitmap.Not(); - + public Roaring32Bitmap NotRange(uint start, uint end) => _bitmap.NotRange(start, end); - + public Roaring32Bitmap And(Roaring32BitmapBase bitmap) => _bitmap.And(bitmap); - + public ulong AndCount(Roaring32BitmapBase bitmap) => _bitmap.AndCount(bitmap); - + public Roaring32Bitmap AndNot(Roaring32BitmapBase bitmap) => _bitmap.AndNot(bitmap); - + public ulong AndNotCount(Roaring32BitmapBase bitmap) => _bitmap.AndNotCount(bitmap); - + public Roaring32Bitmap Or(Roaring32BitmapBase bitmap) => _bitmap.Or(bitmap); - + public ulong OrCount(Roaring32BitmapBase bitmap) => _bitmap.OrCount(bitmap); - + public Roaring32Bitmap OrMany(Roaring32BitmapBase[] bitmaps) => _bitmap.OrMany(bitmaps); - + public Roaring32Bitmap OrManyHeap(Roaring32BitmapBase[] bitmaps) => _bitmap.OrManyHeap(bitmaps); - + public Roaring32Bitmap LazyOr(Roaring32BitmapBase bitmap, bool bitsetConversion) => _bitmap.LazyOr(bitmap, bitsetConversion); public Roaring32Bitmap Xor(Roaring32BitmapBase bitmap) => _bitmap.Xor(bitmap); @@ -113,21 +112,21 @@ public bool ContainsBulk(BulkContext context, uint value) public Roaring32Bitmap LazyXor(Roaring32BitmapBase bitmap) => _bitmap.LazyXor(bitmap); public bool Overlaps(Roaring32BitmapBase bitmap) => _bitmap.Overlaps(bitmap); - + public bool OverlapsRange(uint start, uint end) => _bitmap.OverlapsRange(start, end); public double GetJaccardIndex(Roaring32BitmapBase bitmap) => _bitmap.GetJaccardIndex(bitmap); - + public void CopyTo(uint[] buffer) => _bitmap.CopyTo(buffer); - + public IEnumerable Values => _bitmap.Values; public uint[] ToArray() => _bitmap.ToArray(); - + public Roaring32Bitmap ToBitmap() => _bitmap.Clone(); - + public Roaring32Bitmap ToBitmapWithOffset(long offset) => _bitmap.CloneWithOffset(offset); - + public nuint GetSerializationBytes(SerializationFormat format = SerializationFormat.Normal) => _bitmap.GetSerializationBytes(format); public byte[] Serialize(SerializationFormat format = SerializationFormat.Normal) => _bitmap.Serialize(format); @@ -135,8 +134,8 @@ public bool ContainsBulk(BulkContext context, uint value) public uint[] Take(ulong count) => _bitmap.Take(count); public Statistics GetStatistics() => _bitmap.GetStatistics(); - + public bool IsValid() => _bitmap.IsValid(); - + public bool IsValid(out string? reason) => _bitmap.IsValid(out reason); } \ No newline at end of file diff --git a/src/Roaring.Net/CRoaring/IReadOnlyRoaring32Bitmap.cs b/src/Roaring.Net/CRoaring/IReadOnlyRoaring32Bitmap.cs index cf5a7dc..9203442 100644 --- a/src/Roaring.Net/CRoaring/IReadOnlyRoaring32Bitmap.cs +++ b/src/Roaring.Net/CRoaring/IReadOnlyRoaring32Bitmap.cs @@ -6,23 +6,23 @@ namespace Roaring.Net.CRoaring; internal interface IReadOnlyRoaring32Bitmap : IDisposable { ulong Count { get; } - + bool IsEmpty { get; } - + uint? Min { get; } - + uint? Max { get; } Roaring32Bitmap Not(); Roaring32Bitmap NotRange(uint start, uint end); - + Roaring32Bitmap And(Roaring32BitmapBase bitmap); - + ulong AndCount(Roaring32BitmapBase bitmap); - + Roaring32Bitmap AndNot(Roaring32BitmapBase bitmap); - + ulong AndNotCount(Roaring32BitmapBase bitmap); Roaring32Bitmap Or(Roaring32BitmapBase bitmap); @@ -52,11 +52,11 @@ internal interface IReadOnlyRoaring32Bitmap : IDisposable bool Contains(uint value); bool ContainsBulk(BulkContext context, uint value); - + bool ContainsRange(uint start, uint end); - + bool ValueEquals(Roaring32BitmapBase? bitmap); - + bool IsSubsetOf(Roaring32BitmapBase? bitmap); bool IsProperSubsetOf(Roaring32BitmapBase? bitmap); @@ -64,7 +64,7 @@ internal interface IReadOnlyRoaring32Bitmap : IDisposable bool IsSupersetOf(Roaring32BitmapBase? bitmap); bool IsProperSupersetOf(Roaring32BitmapBase? bitmap); - + bool TryGetValue(uint index, out uint value); long GetIndex(uint value); @@ -76,7 +76,7 @@ internal interface IReadOnlyRoaring32Bitmap : IDisposable ulong CountRange(uint start, uint end); void CopyTo(uint[] buffer); - + IEnumerable Values { get; } uint[] ToArray(); @@ -86,9 +86,9 @@ internal interface IReadOnlyRoaring32Bitmap : IDisposable nuint GetSerializationBytes(SerializationFormat format = SerializationFormat.Normal); byte[] Serialize(SerializationFormat format = SerializationFormat.Normal); - + Statistics GetStatistics(); - + bool IsValid(); bool IsValid(out string? reason); diff --git a/src/Roaring.Net/CRoaring/NativeMethods.cs b/src/Roaring.Net/CRoaring/NativeMethods.cs index 7af257f..9bb461f 100644 --- a/src/Roaring.Net/CRoaring/NativeMethods.cs +++ b/src/Roaring.Net/CRoaring/NativeMethods.cs @@ -10,7 +10,7 @@ internal static unsafe partial class NativeMethods [LibraryImport("roaring", EntryPoint = "roaring_bitmap_create_with_capacity")] public static partial IntPtr roaring_bitmap_create_with_capacity(uint capacity); #else - [DllImport("roaring")] + [DllImport("roaring")] public static extern IntPtr roaring_bitmap_create_with_capacity(uint capacity); #endif @@ -29,7 +29,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern IntPtr roaring_bitmap_of_ptr(nuint count, uint* values); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_copy")] public static partial IntPtr roaring_bitmap_copy(IntPtr bitmap); @@ -37,7 +37,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern IntPtr roaring_bitmap_copy(IntPtr bitmap); #endif - + [return: MarshalAs(UnmanagedType.I1)] #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_overwrite")] @@ -46,7 +46,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern bool roaring_bitmap_overwrite(IntPtr destination, IntPtr source); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_free")] public static partial void roaring_bitmap_free(IntPtr bitmap); @@ -54,7 +54,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern void roaring_bitmap_free(IntPtr bitmap); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_get_cardinality")] public static partial ulong roaring_bitmap_get_cardinality(IntPtr bitmap); @@ -62,68 +62,68 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern ulong roaring_bitmap_get_cardinality(IntPtr bitmap); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_range_cardinality")] [SuppressMessage("ReSharper", "InconsistentNaming")] public static partial ulong roaring_bitmap_range_cardinality(IntPtr bitmap, ulong range_start, ulong range_end); -#else +#else [DllImport("roaring")] [SuppressMessage("ReSharper", "InconsistentNaming")] public static extern ulong roaring_bitmap_range_cardinality(IntPtr bitmap, ulong range_start, ulong range_end); #endif - + [return: MarshalAs(UnmanagedType.I1)] #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_is_empty")] public static partial bool roaring_bitmap_is_empty(IntPtr bitmap); -#else +#else [DllImport("roaring")] public static extern bool roaring_bitmap_is_empty(IntPtr bitmap); #endif - + [return: MarshalAs(UnmanagedType.I1)] #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_get_copy_on_write")] public static partial bool roaring_bitmap_get_copy_on_write(IntPtr bitmap); -#else +#else [DllImport("roaring")] public static extern bool roaring_bitmap_get_copy_on_write(IntPtr bitmap); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_set_copy_on_write")] public static partial void roaring_bitmap_set_copy_on_write(IntPtr bitmap, [MarshalAs(UnmanagedType.I1)] bool cow); -#else +#else [DllImport("roaring")] public static extern void roaring_bitmap_set_copy_on_write(IntPtr bitmap, [MarshalAs(UnmanagedType.I1)] bool cow); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_add")] public static partial void roaring_bitmap_add(IntPtr bitmap, uint value); -#else +#else [DllImport("roaring")] public static extern void roaring_bitmap_add(IntPtr bitmap, uint value); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_add_many")] public static partial void roaring_bitmap_add_many(IntPtr bitmap, nuint count, uint* values); -#else +#else [DllImport("roaring")] public static extern void roaring_bitmap_add_many(IntPtr bitmap, nuint count, uint* values); #endif - + [return: MarshalAs(UnmanagedType.I1)] #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_add_checked")] public static partial bool roaring_bitmap_add_checked(IntPtr bitmap, uint value); -#else +#else [DllImport("roaring")] public static extern bool roaring_bitmap_add_checked(IntPtr bitmap, uint value); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_add_range_closed")] public static partial void roaring_bitmap_add_range_closed(IntPtr bitmap, uint min, uint max); @@ -131,7 +131,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern void roaring_bitmap_add_range_closed(IntPtr bitmap, uint min, uint max); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_add_offset")] public static partial IntPtr roaring_bitmap_add_offset(IntPtr bitmap, long offset); @@ -139,7 +139,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern IntPtr roaring_bitmap_add_offset(IntPtr bitmap, long offset); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_remove")] public static partial void roaring_bitmap_remove(IntPtr bitmap, uint value); @@ -147,7 +147,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern void roaring_bitmap_remove(IntPtr bitmap, uint value); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_remove_range_closed")] public static partial void roaring_bitmap_remove_range_closed(IntPtr bitmap, uint min, uint max); @@ -459,7 +459,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern bool roaring_bitmap_intersect(IntPtr bitmap1, IntPtr bitmap2); #endif - + [return: MarshalAs(UnmanagedType.I1)] #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_intersect_with_range")] @@ -518,7 +518,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern nuint roaring_bitmap_portable_size_in_bytes(IntPtr bitmap); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_frozen_size_in_bytes")] public static partial nuint roaring_bitmap_frozen_size_in_bytes(IntPtr bitmap); @@ -550,7 +550,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern IntPtr roaring_bitmap_deserialize(byte[] buffer); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_deserialize_safe")] public static partial IntPtr roaring_bitmap_deserialize_safe(byte[] buffer, nuint maxbytes); @@ -574,7 +574,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern IntPtr roaring_bitmap_portable_deserialize(byte[] buffer); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_portable_deserialize_safe")] public static partial IntPtr roaring_bitmap_portable_deserialize_safe(byte[] buffer, nuint maxbytes); @@ -582,7 +582,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern IntPtr roaring_bitmap_portable_deserialize_safe(byte[] buffer, nuint maxbytes); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_portable_deserialize_size")] public static partial nuint roaring_bitmap_portable_deserialize_size(byte[] buffer, nuint maxbytes); @@ -590,7 +590,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern nuint roaring_bitmap_portable_deserialize_size(byte[] buffer, nuint maxbytes); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_frozen_serialize")] public static partial void roaring_bitmap_frozen_serialize(IntPtr bitmap, byte* buffer); @@ -598,7 +598,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern void roaring_bitmap_frozen_serialize(IntPtr bitmap, byte* buffer); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_portable_deserialize_frozen")] public static partial IntPtr roaring_bitmap_portable_deserialize_frozen(byte* buffer); @@ -606,7 +606,7 @@ internal static unsafe partial class NativeMethods [DllImport("roaring")] public static extern IntPtr roaring_bitmap_portable_deserialize_frozen(byte* buffer); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_frozen_view")] public static partial IntPtr roaring_bitmap_frozen_view(byte* buffer, nuint length); @@ -636,7 +636,7 @@ public readonly struct ContainerIt { public readonly int index; } - + [return: MarshalAs(UnmanagedType.I1)] #if NET7_0_OR_GREATER [LibraryImport("roaring")] @@ -663,7 +663,7 @@ public static bool roaring_iterate(IntPtr bitmap, Func iterator) // ReSharper disable once InconsistentNaming public static extern bool roaring_iterate64(IntPtr bitmap, IteratorDelegate iterator, ulong high_bits, IntPtr tag); #endif - + // ReSharper disable once InconsistentNaming public static bool roaring_iterate64(IntPtr bitmap, Func iterator, ulong high_bits) { @@ -672,7 +672,7 @@ public static bool roaring_iterate64(IntPtr bitmap, Func iterator, u public delegate bool IteratorDelegate64(uint value, IntPtr tag); - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_iterator_create")] public static partial IntPtr roaring_iterator_create(IntPtr bitmap); @@ -730,7 +730,7 @@ public static bool roaring_iterate64(IntPtr bitmap, Func iterator, u [DllImport("roaring")] public static extern bool roaring_bitmap_internal_validate(IntPtr bitmap, out IntPtr reasonPtr); #endif - + #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_add_bulk")] public static partial void roaring_bitmap_add_bulk(IntPtr bitmap, IntPtr context, uint value); @@ -738,7 +738,7 @@ public static bool roaring_iterate64(IntPtr bitmap, Func iterator, u [DllImport("roaring")] public static extern void roaring_bitmap_add_bulk(IntPtr bitmap, IntPtr context, uint value); #endif - + [return: MarshalAs(UnmanagedType.I1)] #if NET7_0_OR_GREATER [LibraryImport("roaring", EntryPoint = "roaring_bitmap_contains_bulk")] diff --git a/src/Roaring.Net/CRoaring/Roaring32Bitmap.cs b/src/Roaring.Net/CRoaring/Roaring32Bitmap.cs index debc74f..ea2abf0 100644 --- a/src/Roaring.Net/CRoaring/Roaring32Bitmap.cs +++ b/src/Roaring.Net/CRoaring/Roaring32Bitmap.cs @@ -26,7 +26,7 @@ private static IntPtr CheckBitmapPointer(IntPtr pointer) { throw new InvalidOperationException(ExceptionMessages.UnableToAllocateBitmap); } - + return pointer; } @@ -36,18 +36,18 @@ public static Roaring32Bitmap FromRange(uint start, uint end, uint step = 1) { throw new ArgumentOutOfRangeException(nameof(start), start, ExceptionMessages.StartValueGreaterThenEndValue); } - + if (step == 0) { throw new ArgumentOutOfRangeException(nameof(step), step, ExceptionMessages.StepEqualToZero); } - + return new(NativeMethods.roaring_bitmap_from_range(start, (ulong)end + 1, step)); } public static Roaring32Bitmap FromValues(uint[] values) => FromValues(values, 0U, (nuint)values.Length); - public static Roaring32Bitmap FromValues(uint[] values, nuint offset, nuint count) + public static Roaring32Bitmap FromValues(uint[] values, nuint offset, nuint count) => new(CreatePtrFromValues(values, offset, count)); private static IntPtr CreatePtrFromValues(uint[] values, nuint offset, nuint count) @@ -69,7 +69,7 @@ protected override void Dispose(bool disposing) { return; } - + NativeMethods.roaring_bitmap_free(Pointer); _isDisposed = true; } @@ -77,12 +77,12 @@ protected override void Dispose(bool disposing) ~Roaring32Bitmap() => Dispose(false); public Roaring32Bitmap Clone() => new(NativeMethods.roaring_bitmap_copy(Pointer)); - - public Roaring32Bitmap CloneWithOffset(long offset) + + public Roaring32Bitmap CloneWithOffset(long offset) => new(NativeMethods.roaring_bitmap_add_offset(Pointer, offset)); public bool OverwriteWith(Roaring32BitmapBase source) => NativeMethods.roaring_bitmap_overwrite(Pointer, source.Pointer); - + public void Add(uint value) => NativeMethods.roaring_bitmap_add(Pointer, value); public void AddMany(uint[] values) => AddMany(values, 0, (nuint)values.Length); @@ -93,13 +93,13 @@ public void AddMany(uint[] values, nuint offset, nuint count) { throw new ArgumentOutOfRangeException(nameof(offset), offset, ExceptionMessages.OffsetWithCountGreaterThanNumberOfValues); } - + fixed (uint* valuePtr = values) { NativeMethods.roaring_bitmap_add_many(Pointer, count, valuePtr + offset); } } - + public bool TryAdd(uint value) => NativeMethods.roaring_bitmap_add_checked(Pointer, value); public void AddRange(uint start, uint end) @@ -108,13 +108,13 @@ public void AddRange(uint start, uint end) { throw new ArgumentOutOfRangeException(nameof(start), start, ExceptionMessages.StartValueGreaterThenEndValue); } - + NativeMethods.roaring_bitmap_add_range_closed(Pointer, start, end); } - + public void AddOffset(long offset) { - var previousPtr = Pointer; + IntPtr previousPtr = Pointer; Pointer = NativeMethods.roaring_bitmap_add_offset(Pointer, offset); NativeMethods.roaring_bitmap_free(previousPtr); } @@ -125,10 +125,10 @@ public void AddBulk(BulkContext context, uint value) { throw new ArgumentException(ExceptionMessages.BulkContextBelongsToOtherBitmap, nameof(context)); } - + NativeMethods.roaring_bitmap_add_bulk(Pointer, context.Pointer, value); } - + public void Remove(uint value) => NativeMethods.roaring_bitmap_remove(Pointer, value); public void RemoveMany(uint[] values) => RemoveMany(values, 0, (nuint)values.Length); @@ -139,13 +139,13 @@ public void RemoveMany(uint[] values, nuint offset, nuint count) { throw new ArgumentOutOfRangeException(nameof(offset), offset, ExceptionMessages.OffsetWithCountGreaterThanNumberOfValues); } - + fixed (uint* valuePtr = values) { NativeMethods.roaring_bitmap_remove_many(Pointer, count, valuePtr + offset); } } - + public bool TryRemove(uint value) => NativeMethods.roaring_bitmap_remove_checked(Pointer, value); public void RemoveRange(uint start, uint end) @@ -154,12 +154,12 @@ public void RemoveRange(uint start, uint end) { throw new ArgumentOutOfRangeException(nameof(start), start, ExceptionMessages.StartValueGreaterThenEndValue); } - + NativeMethods.roaring_bitmap_remove_range_closed(Pointer, start, end); } - + public void Clear() => NativeMethods.roaring_bitmap_clear(Pointer); - + public bool Contains(uint value) => NativeMethods.roaring_bitmap_contains(Pointer, value); public bool ContainsRange(uint start, uint end) @@ -168,7 +168,7 @@ public bool ContainsRange(uint start, uint end) { throw new ArgumentOutOfRangeException(nameof(start), start, ExceptionMessages.StartValueGreaterThenEndValue); } - + return NativeMethods.roaring_bitmap_contains_range(Pointer, start, (ulong)end + 1); } @@ -178,7 +178,7 @@ public bool ContainsBulk(BulkContext context, uint value) { throw new ArgumentException(ExceptionMessages.BulkContextBelongsToOtherBitmap, nameof(context)); } - + return NativeMethods.roaring_bitmap_contains_bulk(Pointer, context.Pointer, value); } @@ -208,10 +208,10 @@ public bool IsProperSubsetOf(Roaring32BitmapBase? bitmap) { return false; } - + return NativeMethods.roaring_bitmap_is_strict_subset(Pointer, bitmap.Pointer); } - + public bool IsSupersetOf(Roaring32BitmapBase? bitmap) { if (bitmap == null) @@ -224,29 +224,29 @@ public bool IsSupersetOf(Roaring32BitmapBase? bitmap) { return false; } - + return NativeMethods.roaring_bitmap_is_subset(bitmap.Pointer, Pointer); } - + public bool IsProperSupersetOf(Roaring32BitmapBase? bitmap) { if (bitmap == null) { return false; } - + if (NativeMethods.roaring_bitmap_get_cardinality(bitmap.Pointer) >= NativeMethods.roaring_bitmap_get_cardinality(Pointer)) { return false; } - + return NativeMethods.roaring_bitmap_is_subset(bitmap.Pointer, Pointer); } - + public bool TryGetValue(uint index, out uint value) => NativeMethods.roaring_bitmap_select(Pointer, index, out value); public long GetIndex(uint value) => NativeMethods.roaring_bitmap_get_index(Pointer, value); - + public ulong CountLessOrEqualTo(uint value) => NativeMethods.roaring_bitmap_rank(Pointer, value); /// @@ -265,12 +265,12 @@ public ulong[] CountManyLessOrEqualTo(uint[] values) } public ulong CountRange(uint start, uint end) - { + { if (start > end) { throw new ArgumentOutOfRangeException(nameof(start), start, ExceptionMessages.StartValueGreaterThenEndValue); } - + return NativeMethods.roaring_bitmap_range_cardinality(Pointer, start, (ulong)end + 1); } @@ -283,7 +283,7 @@ public Roaring32Bitmap NotRange(uint start, uint end) { throw new ArgumentOutOfRangeException(nameof(start), start, ExceptionMessages.StartValueGreaterThenEndValue); } - + return new(NativeMethods.roaring_bitmap_flip(Pointer, start, (ulong)end + 1)); } @@ -317,12 +317,12 @@ public ulong AndNotCount(Roaring32BitmapBase bitmap) public Roaring32Bitmap Or(Roaring32BitmapBase bitmap) => new(NativeMethods.roaring_bitmap_or(Pointer, bitmap.Pointer)); - + public ulong OrCount(Roaring32BitmapBase bitmap) => NativeMethods.roaring_bitmap_or_cardinality(Pointer, bitmap.Pointer); - + public Roaring32Bitmap OrMany(Roaring32BitmapBase[] bitmaps) - { + { int length = bitmaps.Length + 1; var pointers = new IntPtr[length]; for (int i = 0; i < bitmaps.Length; i++) @@ -330,7 +330,7 @@ public Roaring32Bitmap OrMany(Roaring32BitmapBase[] bitmaps) pointers[i] = bitmaps[i].Pointer; } pointers[length - 1] = Pointer; - + return new Roaring32Bitmap(NativeMethods.roaring_bitmap_or_many((nuint)pointers.Length, pointers)); } @@ -349,13 +349,13 @@ public Roaring32Bitmap OrManyHeap(Roaring32BitmapBase[] bitmaps) public void IOr(Roaring32BitmapBase bitmap) => NativeMethods.roaring_bitmap_or_inplace(Pointer, bitmap.Pointer); - + public Roaring32Bitmap LazyOr(Roaring32BitmapBase bitmap, bool bitsetConversion) => new(NativeMethods.roaring_bitmap_lazy_or(Pointer, bitmap.Pointer, bitsetConversion)); public void ILazyOr(Roaring32BitmapBase bitmap, bool bitsetConversion) => NativeMethods.roaring_bitmap_lazy_or_inplace(Pointer, bitmap.Pointer, bitsetConversion); - + public Roaring32Bitmap Xor(Roaring32BitmapBase bitmap) => new(NativeMethods.roaring_bitmap_xor(Pointer, bitmap.Pointer)); @@ -364,7 +364,7 @@ public void IXor(Roaring32BitmapBase bitmap) public ulong XorCount(Roaring32BitmapBase bitmap) => NativeMethods.roaring_bitmap_xor_cardinality(Pointer, bitmap.Pointer); - + public Roaring32Bitmap XorMany(params Roaring32BitmapBase[] bitmaps) { int length = bitmaps.Length + 1; @@ -374,32 +374,32 @@ public Roaring32Bitmap XorMany(params Roaring32BitmapBase[] bitmaps) pointers[i] = bitmaps[i].Pointer; } pointers[length - 1] = Pointer; - + return new Roaring32Bitmap(NativeMethods.roaring_bitmap_xor_many((nuint)pointers.Length, pointers)); } - + public Roaring32Bitmap LazyXor(Roaring32BitmapBase bitmap) => new(NativeMethods.roaring_bitmap_lazy_xor(Pointer, bitmap.Pointer)); public void ILazyXor(Roaring32BitmapBase bitmap) => NativeMethods.roaring_bitmap_lazy_xor_inplace(Pointer, bitmap.Pointer); - + public void RepairAfterLazy() => NativeMethods.roaring_bitmap_repair_after_lazy(Pointer); public bool Overlaps(Roaring32BitmapBase bitmap) => NativeMethods.roaring_bitmap_intersect(Pointer, bitmap.Pointer); - + public bool OverlapsRange(uint start, uint end) { if (start > end) { throw new ArgumentOutOfRangeException(nameof(start), start, ExceptionMessages.StartValueGreaterThenEndValue); } - + return NativeMethods.roaring_bitmap_intersect_with_range(Pointer, start, (ulong)end + 1); } - + public double GetJaccardIndex(Roaring32BitmapBase bitmap) => NativeMethods.roaring_bitmap_jaccard_index(Pointer, bitmap.Pointer); @@ -423,7 +423,7 @@ public nuint GetSerializationBytes(SerializationFormat format = SerializationFor SerializationFormat.Frozen => NativeMethods.roaring_bitmap_frozen_size_in_bytes(Pointer), _ => throw new ArgumentOutOfRangeException(nameof(format), format, ExceptionMessages.UnsupportedSerializationFormat) }; - + public byte[] Serialize(SerializationFormat format = SerializationFormat.Normal) { byte[] buffer; @@ -453,7 +453,7 @@ public byte[] Serialize(SerializationFormat format = SerializationFormat.Normal) public static Roaring32Bitmap Deserialize(byte[] buffer, SerializationFormat format = SerializationFormat.Normal) { - var ptr = format switch + IntPtr ptr = format switch { SerializationFormat.Normal => NativeMethods.roaring_bitmap_deserialize_safe(buffer, (nuint)buffer.Length), SerializationFormat.Portable => NativeMethods.roaring_bitmap_portable_deserialize_safe(buffer, (nuint)buffer.Length), @@ -464,13 +464,13 @@ public static Roaring32Bitmap Deserialize(byte[] buffer, SerializationFormat for { throw new InvalidOperationException(ExceptionMessages.DeserializationFailedUnknownReason); } - + return new Roaring32Bitmap(ptr); } - + public static Roaring32Bitmap DeserializeUnsafe(byte[] buffer, SerializationFormat format = SerializationFormat.Normal) { - var ptr = format switch + IntPtr ptr = format switch { SerializationFormat.Normal => NativeMethods.roaring_bitmap_deserialize(buffer), SerializationFormat.Portable => NativeMethods.roaring_bitmap_portable_deserialize(buffer), @@ -481,13 +481,13 @@ public static Roaring32Bitmap DeserializeUnsafe(byte[] buffer, SerializationForm { throw new InvalidOperationException(ExceptionMessages.DeserializationFailedUnknownReason); } - + return new Roaring32Bitmap(ptr); } - + public static nuint GetSerializedSize(byte[] buffer, nuint expectedSize, SerializationFormat format = SerializationFormat.Portable) { - var size = format switch + nuint size = format switch { SerializationFormat.Portable => NativeMethods.roaring_bitmap_portable_deserialize_size(buffer, expectedSize), _ => throw new ArgumentOutOfRangeException(nameof(format), format, ExceptionMessages.UnsupportedSerializationFormat) @@ -511,7 +511,7 @@ public uint[] ToArray() internal Roaring32Bitmap GetFrozenView(nuint size, byte* memoryPtr) { NativeMethods.roaring_bitmap_frozen_serialize(Pointer, memoryPtr); - var ptr = NativeMethods.roaring_bitmap_frozen_view(memoryPtr, size); + IntPtr ptr = NativeMethods.roaring_bitmap_frozen_view(memoryPtr, size); return new Roaring32Bitmap(ptr); } @@ -530,15 +530,15 @@ public uint[] Take(ulong count) public Statistics GetStatistics() { - NativeMethods.roaring_bitmap_statistics(Pointer, out var stats); + NativeMethods.roaring_bitmap_statistics(Pointer, out Statistics stats); return stats; } public bool IsValid() => IsValid(out _); - + public bool IsValid(out string? reason) { - var result = NativeMethods.roaring_bitmap_internal_validate(Pointer, out var reasonPtr); + var result = NativeMethods.roaring_bitmap_internal_validate(Pointer, out IntPtr reasonPtr); reason = Marshal.PtrToStringAnsi(reasonPtr); return result; } diff --git a/src/Roaring.Net/CRoaring/Roaring32BitmapMemory.cs b/src/Roaring.Net/CRoaring/Roaring32BitmapMemory.cs index 4b4ba35..1f55a47 100644 --- a/src/Roaring.Net/CRoaring/Roaring32BitmapMemory.cs +++ b/src/Roaring.Net/CRoaring/Roaring32BitmapMemory.cs @@ -9,21 +9,21 @@ namespace Roaring.Net.CRoaring; public sealed unsafe class Roaring32BitmapMemory : IDisposable { public nuint Size { get; } - + internal readonly byte* MemoryPtr; private bool _isDisposed; private bool _isDisposable; - - private readonly HashSet _bitmapReferences = new(); - + + private readonly HashSet _bitmapReferences = new(); + public Roaring32BitmapMemory(nuint size) { if (size <= 0) { throw new ArgumentOutOfRangeException(nameof(size), ExceptionMessages.BitmapMemorySizeEqualToZero); } - + Size = size; MemoryPtr = AllocateMemory(size); } @@ -43,7 +43,7 @@ public Span AsSpan() public void Write(ReadOnlySpan buffer) { CheckDisposed(); - + var span = new Span(MemoryPtr, (int)Size); buffer.CopyTo(span); } @@ -51,55 +51,55 @@ public void Write(ReadOnlySpan buffer) public void Write(byte[] buffer, int offset, int count) { CheckDisposed(); - + var span = new Span(MemoryPtr, (int)Size); buffer.AsSpan()[offset..count].CopyTo(span); } - + public ValueTask WriteAsync(ReadOnlySpan buffer, CancellationToken cancellationToken = default) { CheckDisposed(); - + if (cancellationToken.IsCancellationRequested) { return ValueTask.FromCanceled(cancellationToken); } Write(buffer); - + return default; } public ValueTask WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken = default) { CheckDisposed(); - + if (cancellationToken.IsCancellationRequested) { return ValueTask.FromCanceled(cancellationToken); } - + Write(buffer, offset, count); - + return default; } - + public FrozenRoaring32Bitmap ToFrozen(SerializationFormat format = SerializationFormat.Frozen) { CheckDisposed(); - - var ptr = format switch + + IntPtr ptr = format switch { SerializationFormat.Frozen => NativeMethods.roaring_bitmap_frozen_view(MemoryPtr, Size), SerializationFormat.Portable => NativeMethods.roaring_bitmap_portable_deserialize_frozen(MemoryPtr), _ => throw new ArgumentOutOfRangeException(nameof(format), format, ExceptionMessages.UnsupportedSerializationFormat) }; - + if (ptr == IntPtr.Zero) { throw new InvalidOperationException(ExceptionMessages.DeserializationFailedUnknownReason); } - + var bitmap = new FrozenRoaring32Bitmap(ptr, this); _bitmapReferences.Add(bitmap); return bitmap; @@ -111,19 +111,19 @@ private void CheckDisposed() { return; } - + throw new ObjectDisposedException(ExceptionMessages.BitmapMemoryDisposed); } internal void Release(Roaring32BitmapBase bitmap) { _bitmapReferences.Remove(bitmap); - + if (_bitmapReferences.Count > 0 || !_isDisposable) { return; } - + Dispose(); } @@ -134,7 +134,7 @@ public void Dispose() _isDisposable = true; return; } - + Dispose(true); GC.SuppressFinalize(this); } @@ -147,15 +147,15 @@ private void Dispose(bool disposing) } if (MemoryPtr != null) - { + { NativeMemory.AlignedFree(MemoryPtr); } - + if (Size > 0) { - GC.RemoveMemoryPressure((long)Size); + GC.RemoveMemoryPressure((long)Size); } - + _isDisposed = true; } diff --git a/src/Roaring.Net/CRoaring/Roaring32Enumerator.cs b/src/Roaring.Net/CRoaring/Roaring32Enumerator.cs index ac58175..674495b 100644 --- a/src/Roaring.Net/CRoaring/Roaring32Enumerator.cs +++ b/src/Roaring.Net/CRoaring/Roaring32Enumerator.cs @@ -27,12 +27,12 @@ public uint Current internal Roaring32Enumerator(IntPtr bitmap) { - var ptr = NativeMethods.roaring_iterator_create(bitmap); + IntPtr ptr = NativeMethods.roaring_iterator_create(bitmap); if (ptr == IntPtr.Zero) { throw new InvalidOperationException(ExceptionMessages.UnableToAllocateBitmapIterator); } - + _iterator = (NativeMethods.Iterator*)ptr; _isFirst = true; } diff --git a/src/Roaring.Net/CRoaring/Statistics.cs b/src/Roaring.Net/CRoaring/Statistics.cs index 04f940c..a5501e5 100644 --- a/src/Roaring.Net/CRoaring/Statistics.cs +++ b/src/Roaring.Net/CRoaring/Statistics.cs @@ -21,9 +21,9 @@ public readonly struct Statistics public readonly uint MaxValue; public readonly uint MinValue; - + [Obsolete] private readonly ulong ValueSum; - + public readonly ulong Count; } \ No newline at end of file diff --git a/src/Roaring.Net/Roaring.Net.csproj b/src/Roaring.Net/Roaring.Net.csproj index f4ec106..8d827ef 100644 --- a/src/Roaring.Net/Roaring.Net.csproj +++ b/src/Roaring.Net/Roaring.Net.csproj @@ -3,6 +3,8 @@ Roaring.Net net6.0;net8.0 true + true + embedded true diff --git a/test/Roaring.Net.Tests/CRoaring/BulkContextTests/DisposeTests.cs b/test/Roaring.Net.Tests/CRoaring/BulkContextTests/DisposeTests.cs index 7be3aed..2c4aa22 100644 --- a/test/Roaring.Net.Tests/CRoaring/BulkContextTests/DisposeTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/BulkContextTests/DisposeTests.cs @@ -11,9 +11,9 @@ public class Dispose { [Fact] public void Dispose_InvokedMoreThanOnce_BlocksRedundantCalls() - { + { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); var context = BulkContext.For(testObject.Bitmap); // Act && Assert @@ -21,17 +21,17 @@ public void Dispose_InvokedMoreThanOnce_BlocksRedundantCalls() context.Dispose(); } } - + public class Finalizer { [Fact] public void Finalizer_InvokedMoreThanOnce_BlocksRedundantCalls() - { + { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); using var context = BulkContext.For(testObject.Bitmap); - var finalizer = context.GetType().GetMethod("Finalize", BindingFlags.Instance | BindingFlags.NonPublic); - + MethodInfo? finalizer = context.GetType().GetMethod("Finalize", BindingFlags.Instance | BindingFlags.NonPublic); + // Act && Assert Assert.NotNull(finalizer); finalizer.Invoke(context, null); diff --git a/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/ConvertTests.cs b/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/ConvertTests.cs index 0579384..583920b 100644 --- a/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/ConvertTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/ConvertTests.cs @@ -14,34 +14,34 @@ public class ToBitmap public void ToBitmap_Always_CreatesNewInstanceOfBitmap() { // Act - using var testObject = FrozenRoaring32BitmapTestObjectFactory.Default.GetDefault(); + using FrozenRoaring32BitmapTestObject testObject = FrozenRoaring32BitmapTestObjectFactory.Default.GetDefault(); // Act - var actual = testObject.Bitmap.ToBitmap(); + Roaring32Bitmap actual = testObject.Bitmap.ToBitmap(); // Assert Assert.Equal(testObject.Bitmap.Values, actual.Values); } - + [Fact] public void ToBitmap_DestroyOriginalBitmap_NewBitmapIsSillUsable() { // Act - var testObject = FrozenRoaring32BitmapTestObjectFactory.Default.GetDefault(); + FrozenRoaring32BitmapTestObject testObject = FrozenRoaring32BitmapTestObjectFactory.Default.GetDefault(); var expectedValues = testObject.Bitmap.Values.ToList(); - + // Act - var actual = testObject.Bitmap.ToBitmap(); + Roaring32Bitmap actual = testObject.Bitmap.ToBitmap(); NativeMemory.Clear(testObject.Bitmap.Memory.MemoryPtr, testObject.Bitmap.Memory.Size); testObject.Dispose(); // Assert Assert.Equal(expectedValues, actual.Values); - - using var opBitmap = Roaring32BitmapTestObjectFactory.Default.GetForCount(100); + + using Roaring32BitmapTestObject opBitmap = Roaring32BitmapTestObjectFactory.Default.GetForCount(100); actual.IOr(opBitmap.Bitmap); - Assert.Equal(expectedValues.Concat(opBitmap.Values).OrderBy(x=> x).Distinct(), actual.Values); - + Assert.Equal(expectedValues.Concat(opBitmap.Values).OrderBy(x => x).Distinct(), actual.Values); + actual.Clear(); Assert.True(actual.IsEmpty); } @@ -63,35 +63,35 @@ public void ToBitmapWithOffset_AddsValueToBitmapValues_ReturnsNewBitmapWithExpec uint[] expected, long offset) { // Arrange - using var testObject = FrozenRoaring32BitmapTestObjectFactory.Default.GetFromValues(values); + using FrozenRoaring32BitmapTestObject testObject = FrozenRoaring32BitmapTestObjectFactory.Default.GetFromValues(values); // Act - using var actualBitmap = testObject.Bitmap.ToBitmapWithOffset(offset); + using Roaring32Bitmap actualBitmap = testObject.Bitmap.ToBitmapWithOffset(offset); // Assert var actual = actualBitmap.Values.ToList(); Assert.Equal(expected, actual); Assert.Equal(testObject.Bitmap.Values, values); } - + [Fact] public void ToBitmapWithOffset_DestroyOriginalBitmap_NewBitmapIsSillUsable() { // Act - var testObject = FrozenRoaring32BitmapTestObjectFactory.Default.GetDefault(); + FrozenRoaring32BitmapTestObject testObject = FrozenRoaring32BitmapTestObjectFactory.Default.GetDefault(); var expectedValues = testObject.Bitmap.Values.ToList(); - + // Act - var actual = testObject.Bitmap.ToBitmapWithOffset(0); + Roaring32Bitmap actual = testObject.Bitmap.ToBitmapWithOffset(0); testObject.Dispose(); // Assert Assert.Equal(expectedValues, actual.Values); - - using var opBitmap = Roaring32BitmapTestObjectFactory.Default.GetForCount(100); + + using Roaring32BitmapTestObject opBitmap = Roaring32BitmapTestObjectFactory.Default.GetForCount(100); actual.IOr(opBitmap.Bitmap); - Assert.Equal(expectedValues.Concat(opBitmap.Values).OrderBy(x=> x).Distinct(), actual.Values); - + Assert.Equal(expectedValues.Concat(opBitmap.Values).OrderBy(x => x).Distinct(), actual.Values); + actual.Clear(); Assert.True(actual.IsEmpty); } diff --git a/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/DisposeTests.cs b/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/DisposeTests.cs index b0c6185..efb871d 100644 --- a/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/DisposeTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/DisposeTests.cs @@ -12,73 +12,73 @@ public class Dispose { [Fact] public void Dispose_InvokedMoreThanOnce_BlocksRedundantCalls() - { + { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); using var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); serializedBitmap.CopyTo(bitmapMemory.AsSpan()); - var frozenBitmap = bitmapMemory.ToFrozen(); + FrozenRoaring32Bitmap frozenBitmap = bitmapMemory.ToFrozen(); // Act && Assert frozenBitmap.Dispose(); frozenBitmap.Dispose(); } - + [Fact] public void Dispose_MemoryObject_ReleasesMemoryObject() - { + { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); serializedBitmap.CopyTo(bitmapMemory.AsSpan()); - var frozenBitmap = bitmapMemory.ToFrozen(); + FrozenRoaring32Bitmap frozenBitmap = bitmapMemory.ToFrozen(); bitmapMemory.Dispose(); - + // Act && Assert frozenBitmap.Dispose(); - + // Act Assert.Throws(() => bitmapMemory.AsSpan()); } } - + public class Finalizer { [Fact] public void Finalizer_InvokedMoreThanOnce_BlocksRedundantCalls() - { + { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); using var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); serializedBitmap.CopyTo(bitmapMemory.AsSpan()); - using var frozenBitmap = bitmapMemory.ToFrozen(); - var finalizer = frozenBitmap.GetType().GetMethod("Finalize", BindingFlags.Instance | BindingFlags.NonPublic); - + using FrozenRoaring32Bitmap frozenBitmap = bitmapMemory.ToFrozen(); + MethodInfo? finalizer = frozenBitmap.GetType().GetMethod("Finalize", BindingFlags.Instance | BindingFlags.NonPublic); + // Act && Assert Assert.NotNull(finalizer); finalizer.Invoke(frozenBitmap, null); finalizer.Invoke(frozenBitmap, null); } - + [Fact] public void Finalizer_MemoryObject_ReleasesMemoryObject() - { + { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); serializedBitmap.CopyTo(bitmapMemory.AsSpan()); - using var frozenBitmap = bitmapMemory.ToFrozen(); + using FrozenRoaring32Bitmap frozenBitmap = bitmapMemory.ToFrozen(); bitmapMemory.Dispose(); - var finalizer = frozenBitmap.GetType().GetMethod("Finalize", BindingFlags.Instance | BindingFlags.NonPublic); + MethodInfo? finalizer = frozenBitmap.GetType().GetMethod("Finalize", BindingFlags.Instance | BindingFlags.NonPublic); Assert.NotNull(finalizer); - + // Act finalizer.Invoke(frozenBitmap, null); - + // Act Assert.Throws(() => bitmapMemory.AsSpan()); } diff --git a/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/FrozenRoaring32BitmapTestObject.cs b/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/FrozenRoaring32BitmapTestObject.cs index 08589b4..01ff3d8 100644 --- a/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/FrozenRoaring32BitmapTestObject.cs +++ b/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/FrozenRoaring32BitmapTestObject.cs @@ -8,13 +8,13 @@ internal sealed class FrozenRoaring32BitmapTestObject : IRoaring32BitmapTestObje Roaring32BitmapBase IRoaring32BitmapTestObject.Bitmap => Bitmap; public FrozenRoaring32Bitmap Bitmap { get; private set; } public uint[] Values { get; } - + public FrozenRoaring32BitmapTestObject(FrozenRoaring32Bitmap bitmap, uint[] values) { Bitmap = bitmap; Values = values; } - + public void Dispose() { Bitmap?.Dispose(); diff --git a/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/FrozenRoaring32BitmapTestObjectFactory.cs b/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/FrozenRoaring32BitmapTestObjectFactory.cs index b294897..9815f4d 100644 --- a/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/FrozenRoaring32BitmapTestObjectFactory.cs +++ b/test/Roaring.Net.Tests/CRoaring/FrozenRoaring32BitmapTests/FrozenRoaring32BitmapTestObjectFactory.cs @@ -6,10 +6,10 @@ namespace Roaring.Net.Tests.CRoaring.FrozenRoaring32BitmapTests; internal class FrozenRoaring32BitmapTestObjectFactory : Roaring32BitmapTestObjectFactoryBase { public static FrozenRoaring32BitmapTestObjectFactory Default { get; } = new(); - + protected override FrozenRoaring32BitmapTestObject CreateBitmapObject(Roaring32Bitmap bitmap, uint[] values) { - var frozenBitmap = bitmap.ToFrozen(); + FrozenRoaring32Bitmap frozenBitmap = bitmap.ToFrozen(); bitmap.Dispose(); return new FrozenRoaring32BitmapTestObject(frozenBitmap, values); } diff --git a/test/Roaring.Net.Tests/CRoaring/IRoaring32BitmapTestObject.cs b/test/Roaring.Net.Tests/CRoaring/IRoaring32BitmapTestObject.cs index d6635ad..002c0f7 100644 --- a/test/Roaring.Net.Tests/CRoaring/IRoaring32BitmapTestObject.cs +++ b/test/Roaring.Net.Tests/CRoaring/IRoaring32BitmapTestObject.cs @@ -1,5 +1,6 @@ -using System; + using Roaring.Net.CRoaring; +using System; namespace Roaring.Net.Tests.CRoaring; diff --git a/test/Roaring.Net.Tests/CRoaring/InlineMatrixTestObjectAttribute.cs b/test/Roaring.Net.Tests/CRoaring/InlineMatrixTestObjectAttribute.cs index 7d96ebe..42b30e1 100644 --- a/test/Roaring.Net.Tests/CRoaring/InlineMatrixTestObjectAttribute.cs +++ b/test/Roaring.Net.Tests/CRoaring/InlineMatrixTestObjectAttribute.cs @@ -2,8 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; -using Roaring.Net.Tests.CRoaring.FrozenRoaring32BitmapTests; -using Roaring.Net.Tests.CRoaring.Roaring32BitmapTests; using Xunit.Sdk; namespace Roaring.Net.Tests.CRoaring; @@ -11,33 +9,33 @@ namespace Roaring.Net.Tests.CRoaring; [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] internal sealed class InlineMatrixTestObjectAttribute(params object[] data) : DataAttribute { - private static readonly TestObjectMatrix[] - Matrix2x2 = TestObjectFactories.Instances.SelectMany(factoryX => TestObjectFactories.Instances.Select(factoryY => + private static readonly TestObjectMatrix[] + Matrix2x2 = TestObjectFactories.Instances.SelectMany(factoryX => TestObjectFactories.Instances.Select(factoryY => new TestObjectMatrix(factoryX, factoryY)) .ToList()) .ToArray(); private static readonly object[] Matrix2x2Objects = Matrix2x2.Cast().ToArray(); - - private static readonly TestObjectMatrix[] - Matrix3x3 = Matrix2x2.SelectMany(factory => TestObjectFactories.Instances.Select(factoryZ => + + private static readonly TestObjectMatrix[] + Matrix3x3 = Matrix2x2.SelectMany(factory => TestObjectFactories.Instances.Select(factoryZ => new TestObjectMatrix(factory.X, factory.Y, factoryZ)) .ToList()) .ToArray(); - + private static readonly object[] Matrix3x3Objects = Matrix3x3.Cast().ToArray(); - - public override IEnumerable GetData(MethodInfo testMethod) + + public override IEnumerable GetData(MethodInfo testMethod) => GetMatrix(testMethod).Select(item => data.Append(item).ToArray()); private static object[] GetMatrix(MethodInfo testMethod) { - var parameter = testMethod.GetParameters().Last(); + ParameterInfo parameter = testMethod.GetParameters().Last(); return parameter.ParameterType switch { - _ when parameter.ParameterType == typeof(TestObjectMatrix) + _ when parameter.ParameterType == typeof(TestObjectMatrix) => Matrix2x2Objects, - _ when parameter.ParameterType == typeof(TestObjectMatrix) + _ when parameter.ParameterType == typeof(TestObjectMatrix) => Matrix3x3Objects, _ => throw new InvalidOperationException("Not supported parameter type") }; diff --git a/test/Roaring.Net.Tests/CRoaring/InlineTestObjectAttribute.cs b/test/Roaring.Net.Tests/CRoaring/InlineTestObjectAttribute.cs index 40377d9..7254670 100644 --- a/test/Roaring.Net.Tests/CRoaring/InlineTestObjectAttribute.cs +++ b/test/Roaring.Net.Tests/CRoaring/InlineTestObjectAttribute.cs @@ -10,16 +10,16 @@ namespace Roaring.Net.Tests.CRoaring; public class InlineTestObjectAttribute(params object[] data) : DataAttribute { private static readonly object[] FactoriesObjects = TestObjectFactories.Instances.Cast().ToArray().ToArray(); - - public override IEnumerable GetData(MethodInfo testMethod) + + public override IEnumerable GetData(MethodInfo testMethod) => GetMatrix(testMethod).Select(item => data.Append(item).ToArray()); private static object[] GetMatrix(MethodInfo testMethod) { - var parameter = testMethod.GetParameters().Last(); + ParameterInfo parameter = testMethod.GetParameters().Last(); return parameter.ParameterType switch { - _ when parameter.ParameterType == typeof(IRoaring32BitmapTestObjectFactory) + _ when parameter.ParameterType == typeof(IRoaring32BitmapTestObjectFactory) => FactoriesObjects, _ => throw new InvalidOperationException("Not supported parameter type") }; diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapMemoryTests/DisposeTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapMemoryTests/DisposeTests.cs index 2bd88cb..52c1c26 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapMemoryTests/DisposeTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapMemoryTests/DisposeTests.cs @@ -11,76 +11,76 @@ public class Dispose { [Fact] public void Dispose_HasReferenceToBitmap_DoesNotDisposeAndNotThrowObjectDisposedException() - { + { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); serializedBitmap.CopyTo(bitmapMemory.AsSpan()); - using var referencedBitmap = bitmapMemory.ToFrozen(); + using FrozenRoaring32Bitmap referencedBitmap = bitmapMemory.ToFrozen(); // Act && Assert bitmapMemory.Dispose(); bitmapMemory.AsSpan(); } - + [Fact] public void Dispose_NoReferencesToBitmap_DisposeAndThrowObjectDisposedException() - { + { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); // Act bitmapMemory.Dispose(); - + // Assert Assert.Throws(() => bitmapMemory.AsSpan()); } - + [Fact] public void Dispose_ReferenceBitmapHasBeenDisposedAndNoOtherReferencesToBitmap_DisposeAndThrowObjectDisposedException() - { + { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); serializedBitmap.CopyTo(bitmapMemory.AsSpan()); - var referencedBitmap = bitmapMemory.ToFrozen(); + FrozenRoaring32Bitmap referencedBitmap = bitmapMemory.ToFrozen(); // Act referencedBitmap.Dispose(); bitmapMemory.Dispose(); - + // Assert Assert.Throws(() => bitmapMemory.AsSpan()); } - + [Fact] public void Dispose_ReferenceBitmapHasBeenDisposedAndHasOtherReferencesToBitmap_DoesNotDisposeAndNotThrowObjectDisposedException() - { + { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); serializedBitmap.CopyTo(bitmapMemory.AsSpan()); - var referencedBitmap1 = bitmapMemory.ToFrozen(); - using var referencedBitmap2 = bitmapMemory.ToFrozen(); + FrozenRoaring32Bitmap referencedBitmap1 = bitmapMemory.ToFrozen(); + using FrozenRoaring32Bitmap referencedBitmap2 = bitmapMemory.ToFrozen(); // Act referencedBitmap1.Dispose(); bitmapMemory.Dispose(); - + // Assert bitmapMemory.AsSpan(); } - + [Fact] public void Dispose_InvokedMoreThanOnce_BlocksRedundantCalls() - { + { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapMemoryTests/FrozenBitmapTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapMemoryTests/FrozenBitmapTests.cs index e7eaae8..54c00ca 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapMemoryTests/FrozenBitmapTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapMemoryTests/FrozenBitmapTests.cs @@ -15,14 +15,14 @@ public void ToFrozen_Disposed_ThrowsObjectDisposedException() // Arrange var bitmapMemory = new Roaring32BitmapMemory(10); bitmapMemory.Dispose(); - + // Act && Assert Assert.Throws(() => { bitmapMemory.ToFrozen(); }); } - + [Fact] public void ToFrozen_MemorySizeEqualToZero_ThrowsArgumentOutOfRangeException() { @@ -32,7 +32,7 @@ public void ToFrozen_MemorySizeEqualToZero_ThrowsArgumentOutOfRangeException() using var bitmapMemory = new Roaring32BitmapMemory(0); }); } - + [Fact] public void ToFrozen_NotSupportedSerializationFormat_ThrowsArgumentOutOfRangeException() { @@ -43,7 +43,7 @@ public void ToFrozen_NotSupportedSerializationFormat_ThrowsArgumentOutOfRangeExc bitmapMemory.ToFrozen((SerializationFormat)int.MaxValue); }); } - + [Fact] public void ToFrozen_InvalidDataCannotDeserialize_ThrowsInvalidOperationException() { @@ -54,36 +54,36 @@ public void ToFrozen_InvalidDataCannotDeserialize_ThrowsInvalidOperationExceptio bitmapMemory.ToFrozen(); }); } - + [Fact] public void ToFrozen_FromFrozen_ReturnsValidFrozenBitmap() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); - + // Act using var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); serializedBitmap.CopyTo(bitmapMemory.AsSpan()); - using var frozenBitmap = bitmapMemory.ToFrozen(); - + using FrozenRoaring32Bitmap frozenBitmap = bitmapMemory.ToFrozen(); + // Assert Assert.Equal(bitmap.Values, frozenBitmap.Values); Assert.True(bitmap.IsValid()); } - + [Fact] public void ToFrozen_FromPortable_ReturnsValidFrozenBitmap() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Portable); - + // Act using var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); serializedBitmap.CopyTo(bitmapMemory.AsSpan()); - using var frozenBitmap = bitmapMemory.ToFrozen(SerializationFormat.Portable); - + using FrozenRoaring32Bitmap frozenBitmap = bitmapMemory.ToFrozen(SerializationFormat.Portable); + // Assert Assert.Equal(bitmap.Values, frozenBitmap.Values); Assert.True(bitmap.IsValid()); diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapMemoryTests/WriteTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapMemoryTests/WriteTests.cs index 38cb8d0..787b0c2 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapMemoryTests/WriteTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapMemoryTests/WriteTests.cs @@ -17,32 +17,32 @@ public void AsSpan_Disposed_ThrowsObjectDisposedException() // Arrange var bitmapMemory = new Roaring32BitmapMemory(10); bitmapMemory.Dispose(); - + // Act && Assert Assert.Throws(() => { bitmapMemory.AsSpan(); }); } - + [Fact] public void AsSpan_CopiesDataToSpan_ReturnsValidBitmap() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); - + // Act using var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); serializedBitmap.CopyTo(bitmapMemory.AsSpan()); - using var frozenBitmap = bitmapMemory.ToFrozen(); - + using FrozenRoaring32Bitmap frozenBitmap = bitmapMemory.ToFrozen(); + // Assert Assert.Equal(bitmap.Values, frozenBitmap.Values); Assert.True(bitmap.IsValid()); } } - + public class WriteSpan { [Fact] @@ -51,32 +51,32 @@ public void Write_Disposed_ThrowsObjectDisposedException() // Arrange var bitmapMemory = new Roaring32BitmapMemory(10); bitmapMemory.Dispose(); - + // Act && Assert Assert.Throws(() => { bitmapMemory.Write(Array.Empty().AsSpan()); }); } - + [Fact] public void Write_WritesReadonlySpan_ReturnsValidBitmap() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); - + // Act using var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); bitmapMemory.Write(serializedBitmap.AsSpan()); - using var frozenBitmap = bitmapMemory.ToFrozen(); - + using FrozenRoaring32Bitmap frozenBitmap = bitmapMemory.ToFrozen(); + // Assert Assert.Equal(bitmap.Values, frozenBitmap.Values); Assert.True(bitmap.IsValid()); } } - + public class WriteSpanAsync { [Fact] @@ -85,50 +85,50 @@ public async Task WriteAsync_Disposed_ThrowsObjectDisposedException() // Arrange var bitmapMemory = new Roaring32BitmapMemory(10); bitmapMemory.Dispose(); - + // Act && Assert await Assert.ThrowsAsync(async () => { await bitmapMemory.WriteAsync(Array.Empty().AsSpan()); }); } - + [Fact] public async Task WriteAsync_CanceledCancellationToken_ThrowsTaskCanceledException() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); var cts = new CancellationTokenSource(); await cts.CancelAsync(); - + using var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); - + // Act && Assert await Assert.ThrowsAsync(async () => { await bitmapMemory.WriteAsync(Array.Empty().AsSpan(), cts.Token); }); } - + [Fact] public async Task WriteAsync_WritesReadonlySpan_ReturnsValidBitmap() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); - + // Act using var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); await bitmapMemory.WriteAsync(serializedBitmap.AsSpan()); - using var frozenBitmap = bitmapMemory.ToFrozen(); - + using FrozenRoaring32Bitmap frozenBitmap = bitmapMemory.ToFrozen(); + // Assert Assert.Equal(bitmap.Values, frozenBitmap.Values); Assert.True(bitmap.IsValid()); } } - + public class WriteByteBuffer { [Fact] @@ -137,32 +137,32 @@ public void Write_Disposed_ThrowsObjectDisposedException() // Arrange var bitmapMemory = new Roaring32BitmapMemory(10); bitmapMemory.Dispose(); - + // Act && Assert Assert.Throws(() => { bitmapMemory.Write([], 0, 0); }); } - + [Fact] public void Write_WritesByteArray_ReturnsValidBitmap() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); - + // Act using var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); bitmapMemory.Write(serializedBitmap, 0, serializedBitmap.Length); - using var frozenBitmap = bitmapMemory.ToFrozen(); - + using FrozenRoaring32Bitmap frozenBitmap = bitmapMemory.ToFrozen(); + // Assert Assert.Equal(bitmap.Values, frozenBitmap.Values); Assert.True(bitmap.IsValid()); } } - + public class WriteByteBufferAsync { [Fact] @@ -171,44 +171,44 @@ public async Task WriteAsync_Disposed_ThrowsObjectDisposedException() // Arrange var bitmapMemory = new Roaring32BitmapMemory(10); bitmapMemory.Dispose(); - + // Act && Assert await Assert.ThrowsAsync(async () => { await bitmapMemory.WriteAsync([], 0, 0); }); } - + [Fact] public async Task WriteAsync_CanceledCancellationToken_ThrowsTaskCanceledException() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); var cts = new CancellationTokenSource(); await cts.CancelAsync(); - + using var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); - + // Act && Assert await Assert.ThrowsAsync(async () => { await bitmapMemory.WriteAsync(serializedBitmap, 0, serializedBitmap.Length, cts.Token); }); } - + [Fact] public async Task WriteAsync_WritesByteArray_ReturnsValidBitmap() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var serializedBitmap = bitmap.Serialize(SerializationFormat.Frozen); - + // Act using var bitmapMemory = new Roaring32BitmapMemory((nuint)serializedBitmap.Length); await bitmapMemory.WriteAsync(serializedBitmap, 0, serializedBitmap.Length); - using var frozenBitmap = bitmapMemory.ToFrozen(); - + using FrozenRoaring32Bitmap frozenBitmap = bitmapMemory.ToFrozen(); + // Assert Assert.Equal(bitmap.Values, frozenBitmap.Values); Assert.True(bitmap.IsValid()); diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTestObjectFactoryBase.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTestObjectFactoryBase.cs index 6bd5c7e..1a1dd62 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTestObjectFactoryBase.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTestObjectFactoryBase.cs @@ -13,12 +13,12 @@ internal abstract class Roaring32BitmapTestObjectFactoryBase GetFromValues(values); IRoaring32BitmapTestObject IRoaring32BitmapTestObjectFactory.GetForRange(uint start, uint end) => GetForRange(start, end); IRoaring32BitmapTestObject IRoaring32BitmapTestObjectFactory.GetForRange(uint start, uint end, uint count) => GetForRange(start, end, count); - + public virtual TTestObject GetDefault() => GetForRange(0, uint.MaxValue, count: 1000); public virtual TTestObject GetEmpty() => CreateBitmapObject(new Roaring32Bitmap(), []); public virtual TTestObject GetForCount(uint count) => GetForRange(0, uint.MaxValue, count); - + public virtual TTestObject GetFromValues(uint[] values) => CreateBitmapObject(Roaring32Bitmap.FromValues(values), values); public virtual TTestObject GetForRange(uint start, uint end) => GetForRange(start, end, end - start + 1); diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/AddTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/AddTests.cs index bf83e5c..c08fb1f 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/AddTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/AddTests.cs @@ -13,45 +13,45 @@ public class Add public void Add_EmptyBitmap_AddsValueToBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); - + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + // Act testObject.Bitmap.Add(10); - + // Assert - Assert.Single(testObject.Bitmap.Values, value=> value == 10U); + Assert.Single(testObject.Bitmap.Values, value => value == 10U); Assert.Equal(1U, testObject.Bitmap.Count); } - + [Fact] public void Add_BitmapWithValues_AddsValueToBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); var cardinality = testObject.Bitmap.Count; - Assert.DoesNotContain(testObject.Bitmap.Values, value=> value == 10U); - + Assert.DoesNotContain(testObject.Bitmap.Values, value => value == 10U); + // Act testObject.Bitmap.Add(10); - + // Assert - Assert.Single(testObject.Bitmap.Values, value=> value == 10U); + Assert.Single(testObject.Bitmap.Values, value => value == 10U); Assert.Equal(cardinality + 1, testObject.Bitmap.Count); } - + [Fact] public void Add_AddedValueExistsInBitmap_ValueIsNotAddedToBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); var cardinality = testObject.Bitmap.Count; var addedValue = testObject.Bitmap.Values.ToList()[2]; - + // Act testObject.Bitmap.Add(addedValue); - + // Assert - Assert.Single(testObject.Bitmap.Values, value=> value == addedValue); + Assert.Single(testObject.Bitmap.Values, value => value == addedValue); Assert.Equal(cardinality, testObject.Bitmap.Count); } } @@ -62,46 +62,46 @@ public class AddMany public void AddMany_EmptyBitmap_AddsValuesToBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); - + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + // Act testObject.Bitmap.AddMany([10, 11]); - + // Assert - Assert.Single(testObject.Bitmap.Values, value=> value == 10U); - Assert.Single(testObject.Bitmap.Values, value=> value == 11U); + Assert.Single(testObject.Bitmap.Values, value => value == 10U); + Assert.Single(testObject.Bitmap.Values, value => value == 11U); Assert.Equal(2U, testObject.Bitmap.Count); } - + [Fact] public void AddMany_BitmapWithValues_AddsValueToBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); var cardinality = testObject.Bitmap.Count; - Assert.DoesNotContain(testObject.Bitmap.Values, value=> value == 10U); - Assert.DoesNotContain(testObject.Bitmap.Values, value=> value == 11U); - + Assert.DoesNotContain(testObject.Bitmap.Values, value => value == 10U); + Assert.DoesNotContain(testObject.Bitmap.Values, value => value == 11U); + // Act testObject.Bitmap.AddMany([10, 11]); - + // Assert - Assert.Single(testObject.Bitmap.Values, value=> value == 10U); - Assert.Single(testObject.Bitmap.Values, value=> value == 11U); + Assert.Single(testObject.Bitmap.Values, value => value == 10U); + Assert.Single(testObject.Bitmap.Values, value => value == 11U); Assert.Equal(cardinality + 2, testObject.Bitmap.Count); } - + [Fact] public void AddMany_AddedValueExistsInBitmap_ValueIsNotAddedToBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); var cardinality = testObject.Bitmap.Count; var addedValues = testObject.Bitmap.Values.ToList()[2..10].ToArray(); - + // Act testObject.Bitmap.AddMany(addedValues); - + // Assert Assert.Contains(testObject.Bitmap.Values, value => addedValues.Contains(value)); Assert.Equal(cardinality, testObject.Bitmap.Count); @@ -111,33 +111,33 @@ public void AddMany_AddedValueExistsInBitmap_ValueIsNotAddedToBitmap() public class AddMany_WithOffset { [Theory] - [InlineData(new uint[] {0, 1, 2, 3, 4}, 0, 5)] - [InlineData(new uint[] {0, 1, 2, 3, 4}, 4, 1)] - [InlineData(new uint[] {0, 1, 2, 3, 4}, 3, 2)] - [InlineData(new uint[] {0, 1, 2, 3, 4}, 1, 2)] - [InlineData(new uint[] {0, 1, 2, 3, 4}, 0, 0)] - [InlineData(new uint[] {1, 2, uint.MaxValue}, 0, 3)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, 0, 5)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, 4, 1)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, 3, 2)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, 1, 2)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, 0, 0)] + [InlineData(new uint[] { 1, 2, uint.MaxValue }, 0, 3)] public void AddMany_WithCorrectOffsetAndCount_AddsValuesToBitmap(uint[] values, uint offset, uint count) { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); - + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + // Act testObject.Bitmap.AddMany(values, offset, count); // Assert Assert.Equal(values[(int)offset..((int)offset + (int)count)], testObject.Bitmap.Values.ToArray()); } - + [Theory] - [InlineData(new uint[] {0, 1, 2, 3, 4}, 0, 6)] - [InlineData(new uint[] {0, 1, 2, 3, 4}, 5, 1)] - [InlineData(new uint[] {0, 1, 2, 3, 4}, 4, 2)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, 0, 6)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, 5, 1)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, 4, 2)] public void AddMany_OffsetAndCountOutOfAllowedRange_ThrowsArgumentOutOfRangeException(uint[] values, uint offset, uint count) { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); - + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + // Act && Assert Assert.Throws(() => { @@ -152,48 +152,48 @@ public class TryAdd public void TryAdd_EmptyBitmap_AddsValueToBitmapAndReturnsTrue() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); - + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + // Act var actual = testObject.Bitmap.TryAdd(10); - + // Assert Assert.True(actual); - Assert.Single(testObject.Bitmap.Values, value=> value == 10U); + Assert.Single(testObject.Bitmap.Values, value => value == 10U); Assert.Equal(1U, testObject.Bitmap.Count); } - + [Fact] public void TryAdd_BitmapWithValues_AddsValueToBitmapAndReturnsTrue() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); var cardinality = testObject.Bitmap.Count; - Assert.DoesNotContain(testObject.Bitmap.Values, value=> value == 10U); - + Assert.DoesNotContain(testObject.Bitmap.Values, value => value == 10U); + // Act var actual = testObject.Bitmap.TryAdd(10); - + // Assert Assert.True(actual); - Assert.Single(testObject.Bitmap.Values, value=> value == 10U); + Assert.Single(testObject.Bitmap.Values, value => value == 10U); Assert.Equal(cardinality + 1, testObject.Bitmap.Count); } - + [Fact] public void TryAdd_AddedValueExistsInBitmap_ValueIsNotAddedToBitmapAndReturnsFalse() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); var cardinality = testObject.Bitmap.Count; var addedValue = testObject.Bitmap.Values.ToList()[2]; - + // Act var actual = testObject.Bitmap.TryAdd(addedValue); - + // Assert Assert.False(actual); - Assert.Single(testObject.Bitmap.Values, value=> value == addedValue); + Assert.Single(testObject.Bitmap.Values, value => value == addedValue); Assert.Equal(cardinality, testObject.Bitmap.Count); } } @@ -206,7 +206,7 @@ public class AddRange public void AddRange_ArgumentsOutOfAllowedRange_ThrowsArgumentOutOfRangeException(uint start, uint end) { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); // Act && Assert Assert.Throws(() => testObject.Bitmap.AddRange(start, end)); @@ -221,7 +221,7 @@ public void AddRange_ArgumentsOutOfAllowedRange_ThrowsArgumentOutOfRangeExceptio public void AddRange_CorrectRange_BitmapContainsExpectedValues(uint start, uint end) { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); // Act testObject.Bitmap.AddRange(start, end); @@ -235,23 +235,23 @@ public void AddRange_CorrectRange_BitmapContainsExpectedValues(uint start, uint Assert.Equal(expected, actual); } } - + public class AddOffset { [Theory] - [InlineData(new uint[] { }, new uint[] { },10)] - [InlineData(new uint[] { 0, 1, 2, 3, 4 },new uint[] { 5, 6, 7, 8, 9 }, 5)] - [InlineData(new uint[] { 0, 1, 2, 3, 4 },new uint[] { 0, 1, 2 }, -2)] - [InlineData(new uint[] { 0, 1, 2, 3, 4 }, new uint[] { },-5)] - [InlineData(new uint[] { 0, 2, 4, 6, 8 }, new uint[] { 10, 12, 14, 16, 18 },10)] + [InlineData(new uint[] { }, new uint[] { }, 10)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, new uint[] { 5, 6, 7, 8, 9 }, 5)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, new uint[] { 0, 1, 2 }, -2)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, new uint[] { }, -5)] + [InlineData(new uint[] { 0, 2, 4, 6, 8 }, new uint[] { 10, 12, 14, 16, 18 }, 10)] [InlineData(new uint[] { 0, 1, 2, 3, 4, uint.MaxValue }, new uint[] { 1, 2, 3, 4, 5 }, 1)] - [InlineData(new uint[] { uint.MaxValue - 1, uint.MaxValue }, new uint[] { uint.MaxValue },1)] - [InlineData(new uint[] { 0 }, new uint[] { uint.MaxValue },uint.MaxValue)] - [InlineData(new uint[] { uint.MaxValue }, new uint[] { 0 },-uint.MaxValue)] + [InlineData(new uint[] { uint.MaxValue - 1, uint.MaxValue }, new uint[] { uint.MaxValue }, 1)] + [InlineData(new uint[] { 0 }, new uint[] { uint.MaxValue }, uint.MaxValue)] + [InlineData(new uint[] { uint.MaxValue }, new uint[] { 0 }, -uint.MaxValue)] public void AddOffset_AddsValueToBitmapValues_BitmapContainsExpectedValues(uint[] values, uint[] expected, long offset) { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values); // Act testObject.Bitmap.AddOffset(offset); @@ -261,70 +261,70 @@ public void AddOffset_AddsValueToBitmapValues_BitmapContainsExpectedValues(uint[ Assert.Equal(expected, actual); } } - + public class AddBulk { [Fact] public void AddBulk_DifferentBitmaps_ThrowsArgumentException() { // Arrange - using var testObject1 = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); - using var testObject2 = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + using Roaring32BitmapTestObject testObject1 = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + using Roaring32BitmapTestObject testObject2 = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); using var context = BulkContext.For(testObject1.Bitmap); - + // Act && Assert Assert.Throws(() => { testObject2.Bitmap.AddBulk(context, 10); }); } - + [Fact] public void AddBulk_EmptyBitmap_AddsValueToBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); using var context = BulkContext.For(testObject.Bitmap); - + // Act testObject.Bitmap.AddBulk(context, 10); - + // Assert - Assert.Single(testObject.Bitmap.Values, value=> value == 10U); + Assert.Single(testObject.Bitmap.Values, value => value == 10U); Assert.Equal(1U, testObject.Bitmap.Count); } - + [Fact] public void AddBulk_BitmapWithValues_AddsValueToBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); var cardinality = testObject.Bitmap.Count; - Assert.DoesNotContain(testObject.Bitmap.Values, value=> value == 10U); + Assert.DoesNotContain(testObject.Bitmap.Values, value => value == 10U); using var context = BulkContext.For(testObject.Bitmap); - + // Act testObject.Bitmap.AddBulk(context, 10); - + // Assert - Assert.Single(testObject.Bitmap.Values, value=> value == 10U); + Assert.Single(testObject.Bitmap.Values, value => value == 10U); Assert.Equal(cardinality + 1, testObject.Bitmap.Count); } - + [Fact] public void AddBulk_AddedValueExistsInBitmap_ValueIsNotAddedToBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); var cardinality = testObject.Bitmap.Count; var addedValue = testObject.Bitmap.Values.ToList()[2]; using var context = BulkContext.For(testObject.Bitmap); - + // Act testObject.Bitmap.AddBulk(context, addedValue); - + // Assert - Assert.Single(testObject.Bitmap.Values, value=> value == addedValue); + Assert.Single(testObject.Bitmap.Values, value => value == addedValue); Assert.Equal(cardinality, testObject.Bitmap.Count); } } diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/AndTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/AndTests.cs index 8f75010..67c5bc9 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/AndTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/AndTests.cs @@ -1,4 +1,5 @@ using System.Linq; +using Roaring.Net.CRoaring; using Xunit; namespace Roaring.Net.Tests.CRoaring.Roaring32BitmapTests; @@ -8,117 +9,117 @@ public class AndTests public class And { [Theory] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] - public void And_BitmapsWithDifferentValues_ReturnsIntersectionOfBitmaps(uint[] values1, uint[] values2, + [InlineMatrixTestObject(new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] + public void And_BitmapsWithDifferentValues_ReturnsIntersectionOfBitmaps(uint[] values1, uint[] values2, TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues(values1); - using var testObject2 = matrix.Y.GetFromValues(values2); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues(values1); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues(values2); + // Act - using var actual = testObject1.ReadOnlyBitmap.And(testObject2.Bitmap); - + using Roaring32Bitmap actual = testObject1.ReadOnlyBitmap.And(testObject2.Bitmap); + // Assert Assert.Equal(values1.Intersect(values2), actual.Values); } } - - public class AndCount + + public class AndCount { [Theory] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] - public void AndCount_BitmapsWithDifferentValues_ReturnsCountAfterIntersectionOfBitmaps(uint[] values1, uint[] values2, + [InlineMatrixTestObject(new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] + public void AndCount_BitmapsWithDifferentValues_ReturnsCountAfterIntersectionOfBitmaps(uint[] values1, uint[] values2, TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues(values1); - using var testObject2 = matrix.Y.GetFromValues(values2); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues(values1); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues(values2); + // Act var actual = testObject1.ReadOnlyBitmap.AndCount(testObject2.Bitmap); - + // Assert Assert.Equal((uint)values1.Intersect(values2).Count(), actual); } } - + public class IAnd { [Theory] - [InlineData(new uint[]{ }, new uint[]{ })] - [InlineData(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineData(new uint[]{ 1 }, new uint[]{ })] - [InlineData(new uint[]{ }, new uint[]{ 1 })] - [InlineData(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineData(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] + [InlineData(new uint[] { }, new uint[] { })] + [InlineData(new uint[] { 1 }, new uint[] { 1 })] + [InlineData(new uint[] { 1 }, new uint[] { })] + [InlineData(new uint[] { }, new uint[] { 1 })] + [InlineData(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineData(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] public void IAnd_BitmapsWithDifferentValues_ReturnsIntersectionOfBitmaps(uint[] values1, uint[] values2) { // Arrange - using var testObject1 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values1); - using var testObject2 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values2); - + using Roaring32BitmapTestObject testObject1 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values1); + using Roaring32BitmapTestObject testObject2 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values2); + // Act testObject1.Bitmap.IAnd(testObject2.Bitmap); - + // Assert Assert.Equal(values1.Intersect(values2), testObject1.Bitmap.Values); } } - + public class AndNot { [Theory] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] - public void AndNot_BitmapsWithDifferentValues_ReturnsDifferenceOfBitmaps(uint[] values1, uint[] values2, + [InlineMatrixTestObject(new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] + public void AndNot_BitmapsWithDifferentValues_ReturnsDifferenceOfBitmaps(uint[] values1, uint[] values2, TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues(values1); - using var testObject2 = matrix.Y.GetFromValues(values2); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues(values1); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues(values2); + // Act - using var actual = testObject1.ReadOnlyBitmap.AndNot(testObject2.Bitmap); - + using Roaring32Bitmap actual = testObject1.ReadOnlyBitmap.AndNot(testObject2.Bitmap); + // Assert Assert.Equal(values1.Except(values2), actual.Values); } } - + public class AndNotCount { [Theory] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] - public void AndNotCount_BitmapsWithDifferentValues_ReturnsCountAfterDifferenceOfBitmaps(uint[] values1, uint[] values2, + [InlineMatrixTestObject(new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] + public void AndNotCount_BitmapsWithDifferentValues_ReturnsCountAfterDifferenceOfBitmaps(uint[] values1, uint[] values2, TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues(values1); - using var testObject2 = matrix.Y.GetFromValues(values2); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues(values1); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues(values2); + // Act var actual = testObject1.ReadOnlyBitmap.AndNotCount(testObject2.Bitmap); - + // Assert Assert.Equal((uint)values1.Except(values2).Count(), actual); } @@ -127,21 +128,21 @@ public void AndNotCount_BitmapsWithDifferentValues_ReturnsCountAfterDifferenceOf public class IAndNot { [Theory] - [InlineData(new uint[]{ }, new uint[]{ })] - [InlineData(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineData(new uint[]{ 1 }, new uint[]{ })] - [InlineData(new uint[]{ }, new uint[]{ 1 })] - [InlineData(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineData(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] + [InlineData(new uint[] { }, new uint[] { })] + [InlineData(new uint[] { 1 }, new uint[] { 1 })] + [InlineData(new uint[] { 1 }, new uint[] { })] + [InlineData(new uint[] { }, new uint[] { 1 })] + [InlineData(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineData(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] public void IAndNot_BitmapsWithDifferentValues_ReturnsDifferenceOfBitmaps(uint[] values1, uint[] values2) { // Arrange - using var testObject1 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values1); - using var testObject2 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values2); - + using Roaring32BitmapTestObject testObject1 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values1); + using Roaring32BitmapTestObject testObject2 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values2); + // Act testObject1.Bitmap.IAndNot(testObject2.Bitmap); - + // Assert Assert.Equal(values1.Except(values2), testObject1.Bitmap.Values); } diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/CollectionTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/CollectionTests.cs index b474e8d..69de2b4 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/CollectionTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/CollectionTests.cs @@ -7,93 +7,93 @@ public class CollectionTests public class ToArray { [Theory] - [InlineTestObject(new uint[]{})] - [InlineTestObject(new uint[]{uint.MaxValue})] + [InlineTestObject(new uint[] { })] + [InlineTestObject(new uint[] { uint.MaxValue })] [InlineTestObject(new uint[] { 0, 1, 2, 3, 4 })] public void ToArray_Always_ReturnsArrayWithExpectedValues(uint[] expected, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(expected); - + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(expected); + // Act var actual = testObject.ReadOnlyBitmap.ToArray(); - + // Assert Assert.Equal(expected, actual); } } - + public class CopyTo { [Theory] - [InlineTestObject(new uint[]{})] - [InlineTestObject(new uint[]{uint.MaxValue})] + [InlineTestObject(new uint[] { })] + [InlineTestObject(new uint[] { uint.MaxValue })] [InlineTestObject(new uint[] { 0, 1, 2, 3, 4 })] public void CopyTo_OutputCollectionSizeEqualToNumberOfValues_ReturnsFilledCollection(uint[] expected, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(expected); + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(expected); uint[] actual = new uint[expected.Length]; - + // Act testObject.ReadOnlyBitmap.CopyTo(actual); - + // Assert Assert.Equal(expected, actual); } - + [Theory] [InlineTestObject] public void CopyTo_OutputCollectionIsEmpty_ReturnsEmptyCollection(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues([ 0, 1, 2, 3, 4 ]); + using IRoaring32BitmapTestObject testObject = factory.GetFromValues([0, 1, 2, 3, 4]); uint[] actual = []; - + // Act testObject.ReadOnlyBitmap.CopyTo(actual); - + // Assert Assert.Empty(actual); } - + [Theory] [InlineTestObject] public void CopyTo_OutputCollectionSizeGreaterThanNumberOfValues_ReturnsFilledCollectionFromBeginning(IRoaring32BitmapTestObjectFactory factory) { // Arrange - var expected = new uint[]{0, 1, 2, 3, 4, 0, 0, 0, 0, 0}; + var expected = new uint[] { 0, 1, 2, 3, 4, 0, 0, 0, 0, 0 }; var input = expected[..5]; - using var testObject = factory.GetFromValues(input); + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(input); uint[] actual = new uint[input.Length + 5]; - + // Act testObject.ReadOnlyBitmap.CopyTo(actual); - + // Assert Assert.Equal(expected, actual); } } - + public class Take { [Theory] - [InlineTestObject(20, new uint[]{}, new uint[]{})] + [InlineTestObject(20, new uint[] { }, new uint[] { })] [InlineTestObject(20, new uint[] { 0, 1, 2, 3, 4 }, new uint[] { 0, 1, 2, 3, 4 })] - [InlineTestObject(2, new uint[] { 0, 1, 2, 3, 4 }, new uint[] { 0 ,1 })] - [InlineTestObject(0, new uint[] { 0, 1, 2, 3, 4 }, new uint[] { })] - [InlineTestObject(1, new uint[] { uint.MaxValue }, new uint[] { uint.MaxValue })] + [InlineTestObject(2, new uint[] { 0, 1, 2, 3, 4 }, new uint[] { 0, 1 })] + [InlineTestObject(0, new uint[] { 0, 1, 2, 3, 4 }, new uint[] { })] + [InlineTestObject(1, new uint[] { uint.MaxValue }, new uint[] { uint.MaxValue })] public void Take_ForCount_ReturnsForValuesLimitedToCount(uint count, uint[] values, uint[] expected, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(values); - + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(values); + // Act var actual = testObject.ReadOnlyBitmap.Take(count); - + // Assert Assert.Equal(expected, actual); } } - + } \ No newline at end of file diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/CompareTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/CompareTests.cs index 2c89dc1..a253311 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/CompareTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/CompareTests.cs @@ -12,7 +12,7 @@ public class ValueEquals public void ValueEquals_SameBitmap_ReturnsTrue(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act var actual = testObject.ReadOnlyBitmap.ValueEquals(testObject.Bitmap); @@ -26,8 +26,8 @@ public void ValueEquals_SameBitmap_ReturnsTrue(IRoaring32BitmapTestObjectFactory public void ValueEquals_BitmapsHaveSameValues_ReturnsTrue(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10]); - using var testObject2 = matrix.Y.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0, 10]); // Act var actual = testObject1.ReadOnlyBitmap.ValueEquals(testObject2.Bitmap); @@ -41,8 +41,8 @@ public void ValueEquals_BitmapsHaveSameValues_ReturnsTrue(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10]); - using var testObject2 = matrix.Y.GetFromValues([0, 10, 20]); + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0, 10, 20]); // Act var actual = testObject1.ReadOnlyBitmap.ValueEquals(testObject2.Bitmap); @@ -56,7 +56,7 @@ public void ValueEquals_BitmapsHaveDifferentValues_ReturnsFalse(TestObjectMatrix public void ValueEquals_BitmapIsNull_ReturnsFalse(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject1 = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject1 = factory.GetEmpty(); // Act var actual = testObject1.ReadOnlyBitmap.ValueEquals(null); @@ -73,7 +73,7 @@ public class IsSubsetOf public void IsSubsetOf_BitmapIsNull_ReturnsFalse(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act var actual = testObject.ReadOnlyBitmap.IsSubsetOf(null); @@ -87,7 +87,7 @@ public void IsSubsetOf_BitmapIsNull_ReturnsFalse(IRoaring32BitmapTestObjectFacto public void IsSubsetOf_SameBitmap_ReturnsTrue(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act var actual = testObject.ReadOnlyBitmap.IsSubsetOf(testObject.Bitmap); @@ -95,14 +95,14 @@ public void IsSubsetOf_SameBitmap_ReturnsTrue(IRoaring32BitmapTestObjectFactory // Assert Assert.True(actual); } - + [Theory] [InlineMatrixTestObject] public void IsSubsetOf_EmptyBitmaps_ReturnsFalse(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetEmpty(); - using var testObject2 = matrix.Y.GetEmpty(); + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetEmpty(); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetEmpty(); // Act var actual = testObject1.ReadOnlyBitmap.IsSubsetOf(testObject2.Bitmap); @@ -116,8 +116,8 @@ public void IsSubsetOf_EmptyBitmaps_ReturnsFalse(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10]); - using var testObject2 = matrix.Y.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0, 10]); // Act var actual = testObject1.ReadOnlyBitmap.IsSubsetOf(testObject2.Bitmap); @@ -131,27 +131,27 @@ public void IsSubsetOf_BitmapsHaveSameValues_ReturnsTrue(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10]); - using var testObject2 = matrix.Y.GetFromValues([0, 10, 20]); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0, 10, 20]); + // Act var actual = testObject1.ReadOnlyBitmap.IsSubsetOf(testObject2.Bitmap); - + // Assert Assert.True(actual); } - + [Theory] [InlineMatrixTestObject] public void IsSubsetOf_SecondBitmapNotContainsSomeValuesOfBitmap_ReturnsFalse(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10]); - using var testObject2 = matrix.Y.GetFromValues([0]); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0]); + // Act var actual = testObject1.ReadOnlyBitmap.IsSubsetOf(testObject2.Bitmap); - + // Assert Assert.False(actual); } @@ -164,7 +164,7 @@ public class IsProperSubsetOf public void IsProperSubsetOf_BitmapIsNull_ReturnsFalse(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act var actual = testObject.ReadOnlyBitmap.IsProperSubsetOf(null); @@ -172,13 +172,13 @@ public void IsProperSubsetOf_BitmapIsNull_ReturnsFalse(IRoaring32BitmapTestObjec // Assert Assert.False(actual); } - + [Theory] [InlineTestObject] public void IsProperSubsetOf_SameBitmap_ReturnsFalse(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues([1]); + using IRoaring32BitmapTestObject testObject = factory.GetFromValues([1]); // Act var actual = testObject.ReadOnlyBitmap.IsProperSubsetOf(testObject.Bitmap); @@ -186,14 +186,14 @@ public void IsProperSubsetOf_SameBitmap_ReturnsFalse(IRoaring32BitmapTestObjectF // Assert Assert.False(actual); } - + [Theory] [InlineMatrixTestObject] public void IsProperSubsetOf_EmptyBitmaps_ReturnsFalse(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetEmpty(); - using var testObject2 = matrix.Y.GetEmpty(); + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetEmpty(); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetEmpty(); // Act var actual = testObject1.ReadOnlyBitmap.IsProperSubsetOf(testObject2.Bitmap); @@ -207,8 +207,8 @@ public void IsProperSubsetOf_EmptyBitmaps_ReturnsFalse(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10]); - using var testObject2 = matrix.Y.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0, 10]); // Act var actual = testObject1.ReadOnlyBitmap.IsProperSubsetOf(testObject2.Bitmap); @@ -216,38 +216,38 @@ public void IsProperSubsetOf_BitmapsHaveSameValues_ReturnsFalse(TestObjectMatrix // Assert Assert.False(actual); } - + [Theory] [InlineMatrixTestObject] public void IsProperSubsetOf_SecondBitmapContainsAllValuesOfBitmap_ReturnsTrue(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10]); - using var testObject2 = matrix.Y.GetFromValues([0, 10, 20]); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0, 10, 20]); + // Act var actual = testObject1.ReadOnlyBitmap.IsProperSubsetOf(testObject2.Bitmap); - + // Assert Assert.True(actual); } - + [Theory] [InlineMatrixTestObject] public void IsProperSubsetOf_SecondBitmapNotContainsSomeValuesOfBitmap_ReturnsFalse(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10]); - using var testObject2 = matrix.Y.GetFromValues([0]); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0]); + // Act var actual = testObject1.ReadOnlyBitmap.IsProperSubsetOf(testObject2.Bitmap); - + // Assert Assert.False(actual); } } - + public class IsSupersetOf { [Theory] @@ -255,7 +255,7 @@ public class IsSupersetOf public void IsSupersetOf_BitmapIsNull_ReturnsFalse(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act var actual = testObject.ReadOnlyBitmap.IsSupersetOf(null); @@ -269,7 +269,7 @@ public void IsSupersetOf_BitmapIsNull_ReturnsFalse(IRoaring32BitmapTestObjectFac public void IsSupersetOf_SameBitmap_ReturnsTrue(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act var actual = testObject.ReadOnlyBitmap.IsSupersetOf(testObject.Bitmap); @@ -277,14 +277,14 @@ public void IsSupersetOf_SameBitmap_ReturnsTrue(IRoaring32BitmapTestObjectFactor // Assert Assert.True(actual); } - + [Theory] [InlineMatrixTestObject] public void IsSupersetOf_EmptyBitmaps_ReturnsTrue(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetEmpty(); - using var testObject2 = matrix.Y.GetEmpty(); + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetEmpty(); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetEmpty(); // Act var actual = testObject1.ReadOnlyBitmap.IsSupersetOf(testObject2.Bitmap); @@ -298,8 +298,8 @@ public void IsSupersetOf_EmptyBitmaps_ReturnsTrue(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10]); - using var testObject2 = matrix.Y.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0, 10]); // Act var actual = testObject1.ReadOnlyBitmap.IsSubsetOf(testObject2.Bitmap); @@ -313,32 +313,32 @@ public void IsSupersetOf_BitmapsHaveSameValues_ReturnsTrue(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10, 20 ]); - using var testObject2 = matrix.Y.GetFromValues([0, 10]); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10, 20]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0, 10]); + // Act var actual = testObject1.ReadOnlyBitmap.IsSupersetOf(testObject2.Bitmap); - + // Assert Assert.True(actual); } - + [Theory] [InlineMatrixTestObject] public void IsSupersetOf_BitmapNotContainsSomeValuesOfSecondBitmap_ReturnsFalse(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10]); - using var testObject2 = matrix.Y.GetFromValues([0, 10, 20]); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0, 10, 20]); + // Act var actual = testObject1.ReadOnlyBitmap.IsSupersetOf(testObject2.Bitmap); - + // Assert Assert.False(actual); } } - + public class IsProperSupersetOf { [Theory] @@ -346,7 +346,7 @@ public class IsProperSupersetOf public void IsProperSupersetOf_BitmapIsNull_ReturnsFalse(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act var actual = testObject.ReadOnlyBitmap.IsProperSupersetOf(null); @@ -360,7 +360,7 @@ public void IsProperSupersetOf_BitmapIsNull_ReturnsFalse(IRoaring32BitmapTestObj public void IsProperSupersetOf_SameBitmap_ReturnsFalse(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act var actual = testObject.ReadOnlyBitmap.IsProperSupersetOf(testObject.Bitmap); @@ -368,14 +368,14 @@ public void IsProperSupersetOf_SameBitmap_ReturnsFalse(IRoaring32BitmapTestObjec // Assert Assert.False(actual); } - + [Theory] [InlineMatrixTestObject] public void IsProperSupersetOf_EmptyBitmaps_ReturnsTrue(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetEmpty(); - using var testObject2 = matrix.Y.GetEmpty(); + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetEmpty(); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetEmpty(); // Act var actual = testObject1.ReadOnlyBitmap.IsProperSupersetOf(testObject2.Bitmap); @@ -389,8 +389,8 @@ public void IsProperSupersetOf_EmptyBitmaps_ReturnsTrue(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10]); - using var testObject2 = matrix.Y.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0, 10]); // Act var actual = testObject1.ReadOnlyBitmap.IsProperSupersetOf(testObject2.Bitmap); @@ -404,32 +404,32 @@ public void IsProperSupersetOf_BitmapsHaveSameValues_ReturnsFalse(TestObjectMatr public void IsProperSupersetOf_BitmapContainsAllValuesOfSecondBitmap_ReturnsTrue(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10, 20]); - using var testObject2 = matrix.Y.GetFromValues([0, 10]); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10, 20]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0, 10]); + // Act var actual = testObject1.ReadOnlyBitmap.IsProperSupersetOf(testObject2.Bitmap); - + // Assert Assert.True(actual); } - + [Theory] [InlineMatrixTestObject] public void IsProperSupersetOf_BitmapNotContainsSomeValuesOfSecondBitmap_ReturnsFalse(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10]); - using var testObject2 = matrix.Y.GetFromValues([0, 10, 20]); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([0, 10, 20]); + // Act var actual = testObject1.ReadOnlyBitmap.IsProperSupersetOf(testObject2.Bitmap); - + // Assert Assert.False(actual); } } - + public class Overlaps { [Theory] @@ -437,32 +437,32 @@ public class Overlaps public void Overlaps_IntersectsWithAtLeastOneValue_ReturnsTrue(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10, uint.MaxValue, 1]); - using var testObject2 = matrix.Y.GetFromValues([5, 10, 11]); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10, uint.MaxValue, 1]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([5, 10, 11]); + // Act var actual = testObject1.ReadOnlyBitmap.Overlaps(testObject2.Bitmap); - + // Assert Assert.True(actual); } - + [Theory] [InlineMatrixTestObject] public void Overlaps_NoValuesIntersects_ReturnsFalse(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([0, 10, uint.MaxValue, 1]); - using var testObject2 = matrix.Y.GetFromValues([5, 12, 11]); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([0, 10, uint.MaxValue, 1]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([5, 12, 11]); + // Act var actual = testObject1.ReadOnlyBitmap.Overlaps(testObject2.Bitmap); - + // Assert Assert.False(actual); } } - + public class OverlapsRange { [Theory] @@ -471,45 +471,45 @@ public class OverlapsRange public void OverlapsRange_ArgumentsOutOfAllowedRange_ThrowsArgumentOutOfRangeException(uint start, uint end, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); - + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); + // Act && Assert Assert.Throws(() => testObject.ReadOnlyBitmap.OverlapsRange(start, end)); } - + [Theory] - [InlineTestObject(new uint[] {0, 10, uint.MaxValue}, 0, 0)] - [InlineTestObject(new uint[] {0, 10, uint.MaxValue}, 0, uint.MaxValue)] - [InlineTestObject(new uint[] {0, 10, uint.MaxValue}, 0, 9)] - [InlineTestObject(new uint[] {0, 10, uint.MaxValue}, 1, 10)] - [InlineTestObject(new uint[] {0, 10, uint.MaxValue - 1}, uint.MaxValue - 1, uint.MaxValue)] - [InlineTestObject(new uint[] {0, 10, uint.MaxValue}, uint.MaxValue - 1, uint.MaxValue)] - [InlineTestObject(new uint[] {0, 10, uint.MaxValue}, uint.MaxValue, uint.MaxValue)] + [InlineTestObject(new uint[] { 0, 10, uint.MaxValue }, 0, 0)] + [InlineTestObject(new uint[] { 0, 10, uint.MaxValue }, 0, uint.MaxValue)] + [InlineTestObject(new uint[] { 0, 10, uint.MaxValue }, 0, 9)] + [InlineTestObject(new uint[] { 0, 10, uint.MaxValue }, 1, 10)] + [InlineTestObject(new uint[] { 0, 10, uint.MaxValue - 1 }, uint.MaxValue - 1, uint.MaxValue)] + [InlineTestObject(new uint[] { 0, 10, uint.MaxValue }, uint.MaxValue - 1, uint.MaxValue)] + [InlineTestObject(new uint[] { 0, 10, uint.MaxValue }, uint.MaxValue, uint.MaxValue)] public void OverlapsRange_IntersectsWithAtLeastOneValue_ReturnsTrue(uint[] values, uint start, uint end, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(values); - + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(values); + // Act var actual = testObject.ReadOnlyBitmap.OverlapsRange(start, end); - + // Assert Assert.True(actual); } - + [Theory] - [InlineTestObject(new uint[] { 0, 10, uint.MaxValue}, 1, 9)] - [InlineTestObject(new uint[] { 5, 10, uint.MaxValue}, 0, 4)] - [InlineTestObject(new uint[] { 0, 10, uint.MaxValue}, 11, uint.MaxValue - 1)] - [InlineTestObject(new uint[] { 0, 10, uint.MaxValue - 1}, uint.MaxValue, uint.MaxValue)] + [InlineTestObject(new uint[] { 0, 10, uint.MaxValue }, 1, 9)] + [InlineTestObject(new uint[] { 5, 10, uint.MaxValue }, 0, 4)] + [InlineTestObject(new uint[] { 0, 10, uint.MaxValue }, 11, uint.MaxValue - 1)] + [InlineTestObject(new uint[] { 0, 10, uint.MaxValue - 1 }, uint.MaxValue, uint.MaxValue)] public void OverlapsRange_NoValuesIntersects_ReturnsFalse(uint[] values, uint start, uint end, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(values); - + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(values); + // Act var actual = testObject.ReadOnlyBitmap.OverlapsRange(start, end); - + // Assert Assert.False(actual); } diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/ContainsTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/ContainsTests.cs index b1ac7c2..3841563 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/ContainsTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/ContainsTests.cs @@ -14,7 +14,7 @@ public class Contains public void Contains_EmptyBitmap_ReturnFalse(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act var actual = testObject.ReadOnlyBitmap.Contains(10); @@ -28,7 +28,7 @@ public void Contains_EmptyBitmap_ReturnFalse(IRoaring32BitmapTestObjectFactory f public void Contains_BitmapHasValue_ReturnsTrue(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); var value = testObject.Values.First(); // Act @@ -43,7 +43,7 @@ public void Contains_BitmapHasValue_ReturnsTrue(IRoaring32BitmapTestObjectFactor public void Contains_BitmapDoesNotHaveValue_ReturnsFalse(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); Assert.DoesNotContain(testObject.Values, value => value == 10U); // Act @@ -62,31 +62,31 @@ public class ContainsRange public void ContainsRange_ArgumentsOutOfAllowedRange_ThrowsArgumentOutOfRangeException(uint start, uint end, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); - + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); + // Act && Assert Assert.Throws(() => testObject.ReadOnlyBitmap.ContainsRange(start, end)); } - + [Theory] [InlineTestObject(0, 0, 0, 0, true)] [InlineTestObject(0, 1, 0, 0, true)] [InlineTestObject(0, 100, 0, 0, true)] - [InlineTestObject(0,100, 1, 1, true)] + [InlineTestObject(0, 100, 1, 1, true)] [InlineTestObject(0, 100, 0, 10, true)] [InlineTestObject(200, 300, 0, 10, false)] [InlineTestObject(200, 300, 150, 250, false)] [InlineTestObject(200, 300, 250, 350, false)] [InlineTestObject(200, 300, 100, 350, false)] - [InlineTestObject(uint.MaxValue - 100,uint.MaxValue, uint.MaxValue - 1, uint.MaxValue, true)] - [InlineTestObject(uint.MaxValue - 100,uint.MaxValue, uint.MaxValue, uint.MaxValue, true)] - [InlineTestObject(uint.MaxValue,uint.MaxValue, uint.MaxValue, uint.MaxValue, true)] - [InlineTestObject(uint.MaxValue - 1,uint.MaxValue - 1, uint.MaxValue, uint.MaxValue, false)] + [InlineTestObject(uint.MaxValue - 100, uint.MaxValue, uint.MaxValue - 1, uint.MaxValue, true)] + [InlineTestObject(uint.MaxValue - 100, uint.MaxValue, uint.MaxValue, uint.MaxValue, true)] + [InlineTestObject(uint.MaxValue, uint.MaxValue, uint.MaxValue, uint.MaxValue, true)] + [InlineTestObject(uint.MaxValue - 1, uint.MaxValue - 1, uint.MaxValue, uint.MaxValue, false)] public void ContainsRange_CorrectRange_ReturnsExpectedResult(uint startTest, uint endTest, uint start, uint end, bool expected, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetForRange(startTest, endTest); - + using IRoaring32BitmapTestObject testObject = factory.GetForRange(startTest, endTest); + // Act var actual = testObject.ReadOnlyBitmap.ContainsRange(start, end); @@ -94,7 +94,7 @@ public void ContainsRange_CorrectRange_ReturnsExpectedResult(uint startTest, uin Assert.Equal(expected, actual); } } - + public class ContainsBulk { [Theory] @@ -102,23 +102,23 @@ public class ContainsBulk public void ContainsBulk_DifferentBitmaps_ThrowsArgumentException(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetEmpty(); - using var testObject2 = matrix.Y.GetEmpty(); + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetEmpty(); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetEmpty(); using var context = BulkContext.For(testObject1.Bitmap); - + // Act && Assert Assert.Throws(() => { testObject2.ReadOnlyBitmap.ContainsBulk(context, 10); }); } - + [Theory] [InlineTestObject] public void ContainsBulk_EmptyBitmap_ReturnFalse(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); using var context = BulkContext.For(testObject.Bitmap); // Act @@ -133,7 +133,7 @@ public void ContainsBulk_EmptyBitmap_ReturnFalse(IRoaring32BitmapTestObjectFacto public void ContainsBulk_BitmapHasValue_ReturnsTrue(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); var value = testObject.Values.First(); using var context = BulkContext.For(testObject.Bitmap); @@ -149,7 +149,7 @@ public void ContainsBulk_BitmapHasValue_ReturnsTrue(IRoaring32BitmapTestObjectFa public void ContainsBulk_BitmapDoesNotHaveValue_ReturnsFalse(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); Assert.DoesNotContain(testObject.Values, value => value == 10U); using var context = BulkContext.For(testObject.Bitmap); diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/CountTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/CountTests.cs index 2a9bd70..1834a57 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/CountTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/CountTests.cs @@ -12,7 +12,7 @@ public class Count public void Count_BitmapContainsValues_ReturnsCardinalityOfValues(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); // Act var actual = testObject.ReadOnlyBitmap.Count; @@ -26,7 +26,7 @@ public void Count_BitmapContainsValues_ReturnsCardinalityOfValues(IRoaring32Bitm public void Count_EmptyBitmap_ReturnsZero(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act var actual = testObject.ReadOnlyBitmap.Count; @@ -35,7 +35,7 @@ public void Count_EmptyBitmap_ReturnsZero(IRoaring32BitmapTestObjectFactory fact Assert.Equal(0U, actual); } } - + public class CountLessOrEqualTo { [Theory] @@ -52,40 +52,40 @@ public class CountLessOrEqualTo public void CountLessOrEqualTo_ForValues_ReturnsExpectedNumberOfValues(uint[] values, uint testedValue, uint expected, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(values); - + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(values); + // Act var actual = testObject.ReadOnlyBitmap.CountLessOrEqualTo(testedValue); - + // Assert Assert.Equal(expected, actual); } } - + public class CountManyLessOrEqualTo { [Theory] - [InlineTestObject(new uint[] { }, new uint[] { }, new ulong[] { })] - [InlineTestObject(new uint[] { 0, 1, 2, 3, 4 }, new uint[] { }, new ulong[] { })] + [InlineTestObject(new uint[] { }, new uint[] { }, new ulong[] { })] + [InlineTestObject(new uint[] { 0, 1, 2, 3, 4 }, new uint[] { }, new ulong[] { })] [InlineTestObject(new uint[] { 0, 1, 2, 3, 4 }, new uint[] { 0, 1, 2, 3, 4 }, new ulong[] { 1, 2, 3, 4, 5 })] [InlineTestObject(new uint[] { 0, 1, 2, 3, 4 }, new uint[] { 1, 2, 3, 4, 5 }, new ulong[] { 2, 3, 4, 5, 5 })] - [InlineTestObject(new uint[] { 0, 2, 4, 6, 8 }, new uint[] { 5, 6, 7, 8, 9 }, new ulong[] { 3, 4, 4, 5, 5 })] + [InlineTestObject(new uint[] { 0, 2, 4, 6, 8 }, new uint[] { 5, 6, 7, 8, 9 }, new ulong[] { 3, 4, 4, 5, 5 })] [InlineTestObject(new uint[] { 10, 11, 12 }, new uint[] { 0, 1, 2, 3, 4 }, new ulong[] { 0, 0, 0, 0, 0 })] [InlineTestObject(new uint[] { 0, 1, 2, 3, 4, uint.MaxValue }, new uint[] { 0, 1, 2, 3, 4, uint.MaxValue }, new ulong[] { 1, 2, 3, 4, 5, 6 })] [InlineTestObject(new uint[] { uint.MaxValue - 1, uint.MaxValue }, new uint[] { uint.MaxValue - 1, uint.MaxValue }, new ulong[] { 1, 2 })] public void CountManyLessOrEqualTo_ForValues_ReturnsExpectedNumberOfValues(uint[] values, uint[] testedValues, ulong[] expected, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(values); - + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(values); + // Act var actual = testObject.ReadOnlyBitmap.CountManyLessOrEqualTo(testedValues); - + // Assert Assert.Equal(expected, actual); } } - + public class CountRange { [Theory] @@ -94,12 +94,12 @@ public class CountRange public void CountRange_ArgumentsOutOfAllowedRange_ThrowsArgumentOutOfRangeException(uint start, uint end, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); - + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); + // Act && Assert Assert.Throws(() => testObject.ReadOnlyBitmap.CountRange(start, end)); } - + [Theory] [InlineTestObject(new uint[] { 0, 1, 2, 3, 4 }, 0, 0, 1)] [InlineTestObject(new uint[] { 0, 1, 2, 3, 4 }, 0, 5, 5)] @@ -112,11 +112,11 @@ public void CountRange_ArgumentsOutOfAllowedRange_ThrowsArgumentOutOfRangeExcept public void CountRange_ForValues_ReturnsExpectedNumberOfValues(uint[] values, uint start, uint end, uint expected, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(values); - + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(values); + // Act var actual = testObject.ReadOnlyBitmap.CountRange(start, end); - + // Assert Assert.Equal(expected, actual); } diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/DisposeTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/DisposeTests.cs index 8aacc4d..55e5ec1 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/DisposeTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/DisposeTests.cs @@ -1,5 +1,4 @@ -using System; -using Roaring.Net.CRoaring; +using Roaring.Net.CRoaring; using Roaring.Net.Tests.CRoaring.TestData; using Xunit; @@ -11,10 +10,10 @@ public class Dispose { [Fact] public void Dispose_InvokedMoreThanOnce_BlocksRedundantCalls() - { + { // Arrange - var bitmap = SerializationTestBitmap.GetTestBitmap(); - + Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); + // Act && Assert bitmap.Dispose(); bitmap.Dispose(); diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/EnumerableTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/EnumerableTests.cs index 3c04adf..c25ce37 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/EnumerableTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/EnumerableTests.cs @@ -14,10 +14,10 @@ public class Values public void Values_BitmapContainsValues_EnumeratesBitmap(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); // Act - var actual = testObject.ReadOnlyBitmap.Values; + IEnumerable actual = testObject.ReadOnlyBitmap.Values; // Assert Assert.Equal(testObject.Values, actual); @@ -28,7 +28,7 @@ public void Values_BitmapContainsValues_EnumeratesBitmap(IRoaring32BitmapTestObj public void Values_BitmapIsEmpty_BreaksEnumeration(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act && Assert Assert.Empty(testObject.ReadOnlyBitmap.Values); @@ -39,20 +39,20 @@ public void Values_BitmapIsEmpty_BreaksEnumeration(IRoaring32BitmapTestObjectFac public void Values_Reset_ThrowsNotSupportedException(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); - using var enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); + using IEnumerator enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); // Act && Assert Assert.Throws(() => enumerator.Reset()); } - + [Theory] [InlineTestObject] public void Values_Current_ReturnsFirstElement(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); - using var enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); + using IEnumerator enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); // Act && Assert Assert.Equal(testObject.Values[0], enumerator.Current); @@ -63,8 +63,8 @@ public void Values_Current_ReturnsFirstElement(IRoaring32BitmapTestObjectFactory public void Values_MoveNext_ReturnsNextElement(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); - using var enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); + using IEnumerator enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); // Act enumerator.MoveNext(); @@ -82,21 +82,21 @@ public class Enumerator public void Values_ForNonGenericEnumerator_Current_ReturnsFirstElement(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); - using var enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); + using IEnumerator enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); IEnumerator enumeratorNonGeneric = enumerator; // Act && Assert Assert.Equal(testObject.Values[0], enumeratorNonGeneric.Current); } - + [Theory] [InlineTestObject] public void Values_ForNonGenericEnumerator_MoveNext_ReturnsNextElement(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); - using var enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); + using IEnumerator enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); IEnumerator enumeratorNonGeneric = enumerator; // Act @@ -112,8 +112,8 @@ public void Values_ForNonGenericEnumerator_MoveNext_ReturnsNextElement(IRoaring3 public void Values_ForNonGenericEnumeratorReset_ThrowsNotSupportedException(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); - using var enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); + using IEnumerator enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); IEnumerator enumeratorNonGeneric = enumerator; // Act && Assert @@ -128,11 +128,11 @@ public class Enumerable public void Values_ForNonGenericEnumerable_GetEnumerator_ReturnsEnumerator(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); var enumerable = (IEnumerable)testObject.ReadOnlyBitmap.Values; // Act - var enumerator = enumerable.GetEnumerator(); + IEnumerator enumerator = enumerable.GetEnumerator(); using var enumeratorDisposable = enumerator as IDisposable; // Assert @@ -147,8 +147,8 @@ public class Dispose public void Values_Dispose_CurrentThrowsObjectDisposedException(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); - var enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); + IEnumerator enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); // Act enumerator.Dispose(); @@ -162,8 +162,8 @@ public void Values_Dispose_CurrentThrowsObjectDisposedException(IRoaring32Bitmap public void Values_Dispose_MoveNextThrowsObjectDisposedException(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); - var enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); + IEnumerator enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); // Act enumerator.Dispose(); @@ -177,8 +177,8 @@ public void Values_Dispose_MoveNextThrowsObjectDisposedException(IRoaring32Bitma public void Values_DisposeTwice_IgnoresSecondDispose(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); - var enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); + IEnumerator enumerator = testObject.ReadOnlyBitmap.Values.GetEnumerator(); // Act enumerator.Dispose(); diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/IndexTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/IndexTests.cs index 9db2884..e5cc457 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/IndexTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/IndexTests.cs @@ -14,33 +14,33 @@ public class TryGetValue public void TryGetValue_IndexLessThanBitmapSize_ReturnsTrueAndExpectedValue(uint[] values, uint index, uint expected, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(values); - + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(values); + // Act var actualReturn = testObject.ReadOnlyBitmap.TryGetValue(index, out uint actual); - + // Assert Assert.True(actualReturn); Assert.Equal(expected, actual); } - + [Theory] - [InlineTestObject(new uint[]{}, 1, 0)] + [InlineTestObject(new uint[] { }, 1, 0)] [InlineTestObject(new uint[] { 0, 1, 2, 3, 4 }, 5, 0)] public void TryGetValue_IndexGreaterThanBitmapSize_ReturnsFalseAndZero(uint[] values, uint index, uint expected, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(values); - + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(values); + // Act var actualReturn = testObject.ReadOnlyBitmap.TryGetValue(index, out uint actual); - + // Assert Assert.False(actualReturn); Assert.Equal(expected, actual); - } + } } - + public class GetIndex { [Theory] @@ -55,11 +55,11 @@ public class GetIndex public void GetIndex_ForValues_ReturnsIndexOfValue(uint[] values, uint testedValue, long expected, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(values); - + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(values); + // Act var actual = testObject.ReadOnlyBitmap.GetIndex(testedValue); - + // Assert Assert.Equal(expected, actual); } diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/InitializationTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/InitializationTests.cs index 14bcd94..0c6255b 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/InitializationTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/InitializationTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using Roaring.Net.CRoaring; using Xunit; @@ -18,7 +19,7 @@ public void Ctor_ZeroIntPtr_ThrowsInvalidOperationException() using var uut = new Roaring32Bitmap(IntPtr.Zero); }); } - + [Fact] public void Ctor_Default_CreatesBitmapWithZeroCapacity() { @@ -40,25 +41,25 @@ public void Ctor_WithCapacity_CreatesBitmapWithGivenCapacity() var actual = uut.GetSerializationBytes(); Assert.True(actual > 0); } - + [Fact] public void Ctor_FromValues_InputHasValues_BitmapContainsExpectedValues() { // Arrange var expected = Enumerable.Range(0, 100) - .Select(x=> (uint)x) + .Select(x => (uint)x) .Concat([uint.MaxValue - 1, uint.MaxValue]) .ToArray(); - + // Act using var uut = new Roaring32Bitmap(expected); // Assert - var actual = uut.Values; - + IEnumerable actual = uut.Values; + Assert.Equal(expected, actual); } - + [Fact] public void Ctor_FromValues_InputIsEmpty_BitmapIsEmpty() { @@ -66,8 +67,8 @@ public void Ctor_FromValues_InputIsEmpty_BitmapIsEmpty() using var uut = new Roaring32Bitmap([]); // Assert - var actual = uut.Values; - + IEnumerable actual = uut.Values; + Assert.Empty(actual); } } @@ -113,7 +114,7 @@ public void FromRange_StepGreaterThanRange_BitmapContainsMinValueOfRange() using var uut = Roaring32Bitmap.FromRange(1, 10, 100); // Assert - var actual = uut.Values; + IEnumerable actual = uut.Values; Assert.Equal([1], actual); } @@ -134,7 +135,7 @@ public void FromValues_InputHasValues_BitmapContainsExpectedValues() using var uut = Roaring32Bitmap.FromValues(expected); // Assert - var actual = uut.Values; + IEnumerable actual = uut.Values; Assert.Equal(expected, actual); } @@ -146,11 +147,11 @@ public void FromValues_InputIsEmpty_BitmapIsEmpty() using var uut = Roaring32Bitmap.FromValues([]); // Assert - var actual = uut.Values; + IEnumerable actual = uut.Values; Assert.Empty(actual); - } - + } + [Theory] [InlineData(0, 100)] [InlineData(99, 1)] @@ -161,19 +162,19 @@ public void FromValues_WithCorrectOffsetAndCount_BitmapContainsExpectedValues(ui { // Arrange var values = Enumerable.Range(0, 100) - .Select(x=> (uint)x) + .Select(x => (uint)x) .ToArray(); - + // Act using var uut = Roaring32Bitmap.FromValues(values, offset, count); // Assert - var actual = uut.Values; - var expected = values.Skip((int)offset).Take((int)count); - + IEnumerable actual = uut.Values; + IEnumerable expected = values.Skip((int)offset).Take((int)count); + Assert.Equal(expected, actual); } - + [Theory] [InlineData(0, 101)] [InlineData(100, 1)] @@ -182,9 +183,9 @@ public void FromValues_OffsetAndCountOutOfAllowedRange_ThrowsArgumentOutOfRangeE { // Arrange var values = Enumerable.Range(0, 100) - .Select(x=> (uint)x) + .Select(x => (uint)x) .ToArray(); - + // Act && Assert Assert.Throws(() => { @@ -192,43 +193,43 @@ public void FromValues_OffsetAndCountOutOfAllowedRange_ThrowsArgumentOutOfRangeE }); } } - + public class Clone { [Fact] public void Clone_Always_CreatesNewInstanceOfBitmap() { // Act - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); // Act - var actual = testObject.Bitmap.Clone(); - + Roaring32Bitmap actual = testObject.Bitmap.Clone(); + // Assert Assert.NotEqual(testObject.Bitmap, actual); Assert.Equal(testObject.Bitmap.Values, actual.Values); } } - + public class CloneWithOffset { [Theory] - [InlineData(new uint[] { }, new uint[] { },10)] - [InlineData(new uint[] { 0, 1, 2, 3, 4 },new uint[] { 5, 6, 7, 8, 9 }, 5)] - [InlineData(new uint[] { 0, 1, 2, 3, 4 },new uint[] { 0, 1, 2 }, -2)] - [InlineData(new uint[] { 0, 1, 2, 3, 4 }, new uint[] { },-5)] - [InlineData(new uint[] { 0, 2, 4, 6, 8 }, new uint[] { 10, 12, 14, 16, 18 },10)] + [InlineData(new uint[] { }, new uint[] { }, 10)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, new uint[] { 5, 6, 7, 8, 9 }, 5)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, new uint[] { 0, 1, 2 }, -2)] + [InlineData(new uint[] { 0, 1, 2, 3, 4 }, new uint[] { }, -5)] + [InlineData(new uint[] { 0, 2, 4, 6, 8 }, new uint[] { 10, 12, 14, 16, 18 }, 10)] [InlineData(new uint[] { 0, 1, 2, 3, 4, uint.MaxValue }, new uint[] { 1, 2, 3, 4, 5 }, 1)] - [InlineData(new uint[] { uint.MaxValue - 1, uint.MaxValue }, new uint[] { uint.MaxValue },1)] - [InlineData(new uint[] { 0 }, new uint[] { uint.MaxValue },uint.MaxValue)] - [InlineData(new uint[] { uint.MaxValue }, new uint[] { 0 },-uint.MaxValue)] + [InlineData(new uint[] { uint.MaxValue - 1, uint.MaxValue }, new uint[] { uint.MaxValue }, 1)] + [InlineData(new uint[] { 0 }, new uint[] { uint.MaxValue }, uint.MaxValue)] + [InlineData(new uint[] { uint.MaxValue }, new uint[] { 0 }, -uint.MaxValue)] public void CloneWithOffset_AddsValueToBitmapValues_ReturnsNewBitmapWithExpectedValues(uint[] values, uint[] expected, long offset) { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values); // Act - using var actualBitmap = testObject.Bitmap.CloneWithOffset(offset); + using Roaring32Bitmap actualBitmap = testObject.Bitmap.CloneWithOffset(offset); // Assert var actual = actualBitmap.Values.ToList(); @@ -236,7 +237,7 @@ public void CloneWithOffset_AddsValueToBitmapValues_ReturnsNewBitmapWithExpected Assert.Equal(testObject.Bitmap.Values, values); } } - + public class OverwriteWith { [Theory] @@ -250,8 +251,8 @@ public class OverwriteWith public void OverwriteWith_SourceBitmap_ReplacesDestinationBitmapAndReturnsTrue(uint[] source) { // Arrange - using var sourceObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues(source); - using var destinationObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues([0, 1, 2, 3, 4, uint.MaxValue - 1, uint.MaxValue]); + using Roaring32BitmapTestObject sourceObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues(source); + using Roaring32BitmapTestObject destinationObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues([0, 1, 2, 3, 4, uint.MaxValue - 1, uint.MaxValue]); // Act var actual = destinationObject.Bitmap.OverwriteWith(sourceObject.Bitmap); diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/MaintenanceTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/MaintenanceTests.cs index 701e33e..cfe8e1e 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/MaintenanceTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/MaintenanceTests.cs @@ -12,25 +12,25 @@ public class RepairAfterLazy public void RepairAfterLazy_BitmapIsInconsistent_RepairsBitmap() { // Arrange - using var testObject1 = Roaring32BitmapTestObjectFactory.Default.GetForRange(0, 10_000); - using var testObject2 = Roaring32BitmapTestObjectFactory.Default.GetForRange(uint.MaxValue - 10_000, uint.MaxValue); - using var testObject3 = Roaring32BitmapTestObjectFactory.Default.GetForRange(uint.MaxValue - 10_000, uint.MaxValue); - using var temp = testObject1.Bitmap.LazyOr(testObject2.Bitmap, false); - + using Roaring32BitmapTestObject testObject1 = Roaring32BitmapTestObjectFactory.Default.GetForRange(0, 10_000); + using Roaring32BitmapTestObject testObject2 = Roaring32BitmapTestObjectFactory.Default.GetForRange(uint.MaxValue - 10_000, uint.MaxValue); + using Roaring32BitmapTestObject testObject3 = Roaring32BitmapTestObjectFactory.Default.GetForRange(uint.MaxValue - 10_000, uint.MaxValue); + using Roaring32Bitmap temp = testObject1.Bitmap.LazyOr(testObject2.Bitmap, false); + // Act - using var actual = temp.LazyOr(testObject3.Bitmap, false); + using Roaring32Bitmap actual = temp.LazyOr(testObject3.Bitmap, false); var countBeforeRepair = actual.Count; actual.RepairAfterLazy(); var countAfterRepair = actual.Count; - + // Assert var expectedCount = (uint)testObject1.Values.Union(testObject2.Values).Union(testObject3.Values).Count(); Assert.NotEqual(expectedCount, countBeforeRepair); Assert.Equal(expectedCount, countAfterRepair); } } - + public class Optimize { [Fact] @@ -39,16 +39,16 @@ public void Optimize_BitmapCanBeOptimized_OptimizesBitmap() // Arrange uint[] values = [1, 2, 3, 4, 6, 7, 999991, 999992, 999993, 999994, 999996, 999997]; using var bitmap = new Roaring32Bitmap(values); - + // Act - var statisticsBeforeOptimize = bitmap.GetStatistics(); + Statistics statisticsBeforeOptimize = bitmap.GetStatistics(); bitmap.Optimize(); - var statisticsAfterOptimize = bitmap.GetStatistics(); + Statistics statisticsAfterOptimize = bitmap.GetStatistics(); // Assert Assert.Equal(2U, statisticsBeforeOptimize.ArrayContainerCount); Assert.Equal(0U, statisticsAfterOptimize.ArrayContainerCount); - + Assert.Equal(0U, statisticsBeforeOptimize.RunContainerCount); Assert.Equal(2U, statisticsAfterOptimize.RunContainerCount); } @@ -62,13 +62,13 @@ public void Optimize_BitmapContainsRunCompression_ReturnsTrue() // Act var result = bitmap.Optimize(); - var statisticsAfterOptimize = bitmap.GetStatistics(); + Statistics statisticsAfterOptimize = bitmap.GetStatistics(); // Assert Assert.True(result); Assert.Equal(1U, statisticsAfterOptimize.RunContainerCount); } - + [Fact] public void Optimize_BitmapNotContainRunCompression_ReturnsFalse() { @@ -78,14 +78,14 @@ public void Optimize_BitmapNotContainRunCompression_ReturnsFalse() // Act var result = bitmap.Optimize(); - var statisticsAfterOptimize = bitmap.GetStatistics(); + Statistics statisticsAfterOptimize = bitmap.GetStatistics(); // Assert Assert.False(result); Assert.Equal(0U, statisticsAfterOptimize.RunContainerCount); } } - + public class RemoveRunCompression { [Fact] @@ -93,51 +93,51 @@ public void RemoveRunCompression_BitmapContainsRunCompression_RemovesRunCompress { // Arrange using var bitmap = new Roaring32Bitmap(); - bitmap.AddMany(Enumerable.Range(10, 1_000).Select(x=> (uint)x).ToArray()); - + bitmap.AddMany(Enumerable.Range(10, 1_000).Select(x => (uint)x).ToArray()); + // Act bitmap.Optimize(); - var statisticsBeforeRemoveRunCompression = bitmap.GetStatistics(); + Statistics statisticsBeforeRemoveRunCompression = bitmap.GetStatistics(); var result = bitmap.RemoveRunCompression(); - var statisticsBeforeAfterRunCompression = bitmap.GetStatistics(); - + Statistics statisticsBeforeAfterRunCompression = bitmap.GetStatistics(); + // Assert Assert.True(result); Assert.Equal(1U, statisticsBeforeRemoveRunCompression.ContainerCount); Assert.Equal(0U, statisticsBeforeRemoveRunCompression.ArrayContainerCount); Assert.Equal(1U, statisticsBeforeRemoveRunCompression.RunContainerCount); Assert.Equal(0U, statisticsBeforeRemoveRunCompression.BitsetContainerCount); - + Assert.Equal(1U, statisticsBeforeAfterRunCompression.ContainerCount); Assert.Equal(1U, statisticsBeforeAfterRunCompression.ArrayContainerCount); Assert.Equal(0U, statisticsBeforeAfterRunCompression.RunContainerCount); Assert.Equal(0U, statisticsBeforeAfterRunCompression.BitsetContainerCount); } - + [Fact] public void RemoveRunCompression_BitmapNotContainRunCompression_ReturnsFalse() { // Arrange using var bitmap = new Roaring32Bitmap(); - bitmap.AddMany(Enumerable.Range(1, 2).Select(x=> (uint)x).ToArray()); - + bitmap.AddMany(Enumerable.Range(1, 2).Select(x => (uint)x).ToArray()); + // Act bitmap.Optimize(); - var statisticsBeforeRemoveRunCompression = bitmap.GetStatistics(); + Statistics statisticsBeforeRemoveRunCompression = bitmap.GetStatistics(); var result = bitmap.RemoveRunCompression(); - var statisticsBeforeAfterRunCompression = bitmap.GetStatistics(); - + Statistics statisticsBeforeAfterRunCompression = bitmap.GetStatistics(); + // Assert Assert.False(result); Assert.Equal(0U, statisticsBeforeAfterRunCompression.RunContainerCount); - + Assert.Equal(statisticsBeforeAfterRunCompression.ContainerCount, statisticsBeforeRemoveRunCompression.ContainerCount); Assert.Equal(statisticsBeforeAfterRunCompression.ArrayContainerCount, statisticsBeforeRemoveRunCompression.ArrayContainerCount); Assert.Equal(statisticsBeforeAfterRunCompression.RunContainerCount, statisticsBeforeRemoveRunCompression.RunContainerCount); Assert.Equal(statisticsBeforeAfterRunCompression.BitsetContainerCount, statisticsBeforeRemoveRunCompression.BitsetContainerCount); } } - + public class ShrinkToFit { [Fact] @@ -147,7 +147,7 @@ public void ShrinkToFit_BitmapCanBeShrink_ReturnsSavedBytes() using var bitmap = new Roaring32Bitmap(); bitmap.AddRange(0, 1_000); bitmap.RemoveRange(0, 1_0000); - + // Act var actual = bitmap.ShrinkToFit(); @@ -155,7 +155,7 @@ public void ShrinkToFit_BitmapCanBeShrink_ReturnsSavedBytes() Assert.Equal(0x16U, actual); } } - + public class IsValid { [Theory] @@ -163,40 +163,40 @@ public class IsValid public void IsValid_BitmapIsValid_ReturnsTrue(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); - + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); + // Act var actual = testObject.ReadOnlyBitmap.IsValid(); // Assert Assert.True(actual); } - + [Theory] [InlineMatrixTestObject] public void IsValid_BitmapIsNotValid_ReturnsFalse(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetForRange(0, 10_000); - using var testObject2 = matrix.Y.GetForRange(uint.MaxValue - 10_000, uint.MaxValue); - using var testObject3 = matrix.Z.GetForRange(uint.MaxValue - 10_000, uint.MaxValue); - using var temp = testObject1.ReadOnlyBitmap.LazyOr(testObject2.Bitmap, false); - using var bitmap = temp.LazyOr(testObject3.Bitmap, false); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetForRange(0, 10_000); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetForRange(uint.MaxValue - 10_000, uint.MaxValue); + using IRoaring32BitmapTestObject testObject3 = matrix.Z.GetForRange(uint.MaxValue - 10_000, uint.MaxValue); + using Roaring32Bitmap temp = testObject1.ReadOnlyBitmap.LazyOr(testObject2.Bitmap, false); + using Roaring32Bitmap bitmap = temp.LazyOr(testObject3.Bitmap, false); + // Act var actual = bitmap.IsValid(); // Assert Assert.False(actual); } - + [Theory] [InlineTestObject] public void IsValid_WithReason_BitmapIsValid_ReturnsTrueAndNullReason(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); - + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); + // Act var actual = testObject.ReadOnlyBitmap.IsValid(out var reason); @@ -204,18 +204,18 @@ public void IsValid_WithReason_BitmapIsValid_ReturnsTrueAndNullReason(IRoaring32 Assert.True(actual); Assert.Null(reason); } - + [Theory] [InlineMatrixTestObject] public void IsValid_WithReason_BitmapIsNotValid_ReturnsFalseAndReason(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetForRange(0, 10_000); - using var testObject2 = matrix.Y.GetForRange(uint.MaxValue - 10_000, uint.MaxValue); - using var testObject3 = matrix.Z.GetForRange(uint.MaxValue - 10_000, uint.MaxValue); - using var temp = testObject1.ReadOnlyBitmap.LazyOr(testObject2.Bitmap, false); - using var bitmap = temp.LazyOr(testObject3.Bitmap, false); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetForRange(0, 10_000); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetForRange(uint.MaxValue - 10_000, uint.MaxValue); + using IRoaring32BitmapTestObject testObject3 = matrix.Z.GetForRange(uint.MaxValue - 10_000, uint.MaxValue); + using Roaring32Bitmap temp = testObject1.ReadOnlyBitmap.LazyOr(testObject2.Bitmap, false); + using Roaring32Bitmap bitmap = temp.LazyOr(testObject3.Bitmap, false); + // Act var actual = bitmap.IsValid(out var reason); @@ -231,54 +231,54 @@ public class IsCopyOnWrite public void IsCopyOnWrite_Default_ReturnsFalse() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); - + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + // Act var actual = testObject.Bitmap.IsCopyOnWrite; // Assert Assert.False(actual); } - + [Fact] public void IsCopyOnWrite_CopyOnWriteEnabled_ReturnsTrue() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); - + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + // Act testObject.Bitmap.SetCopyOnWrite(true); var actual = testObject.Bitmap.IsCopyOnWrite; - + // Assert Assert.True(actual); } } - + public class SetCopyOnWrite { [Fact] public void SetCopyOnWrite_WithTrue_EnablesCopyOnWrite() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); - + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + // Act testObject.Bitmap.SetCopyOnWrite(true); - + // Assert Assert.True(testObject.Bitmap.IsCopyOnWrite); } - + [Fact] public void SetCopyOnWrite_WithFalse_DisablesCopyOnWrite() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); - + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + // Act testObject.Bitmap.SetCopyOnWrite(false); - + // Assert Assert.False(testObject.Bitmap.IsCopyOnWrite); } diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/MetricsTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/MetricsTests.cs index 0a2b16d..38bfdf4 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/MetricsTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/MetricsTests.cs @@ -12,8 +12,8 @@ public class GetJaccardIndex public void GetJaccardIndex_ForNotEmptyBitmaps_ReturnsJaccardIndex(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues([1, 2, 3, int.MaxValue]); - using var testObject2 = matrix.Y.GetFromValues([1, 2, 3, 5]); + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues([1, 2, 3, int.MaxValue]); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues([1, 2, 3, 5]); // Act var actual = testObject1.ReadOnlyBitmap.GetJaccardIndex(testObject2.Bitmap); @@ -21,17 +21,17 @@ public void GetJaccardIndex_ForNotEmptyBitmaps_ReturnsJaccardIndex(TestObjectMat // Assert var intersectCount = testObject1.Values.Intersect(testObject2.Values).Count(); var unionCount = testObject1.Values.Union(testObject2.Values).Count(); - + Assert.Equal(intersectCount / (double)unionCount, actual); } - + [Theory] [InlineMatrixTestObject] public void GetJaccardIndex_ForEmptyBitmaps_ReturnsNaN(TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetEmpty(); - using var testObject2 = matrix.Y.GetEmpty(); + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetEmpty(); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetEmpty(); // Act var actual = testObject1.ReadOnlyBitmap.GetJaccardIndex(testObject2.Bitmap); @@ -48,7 +48,7 @@ public class IsEmpty public void IsEmpty_BitmapContainsValues_ReturnsFalse(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); // Act var actual = testObject.ReadOnlyBitmap.IsEmpty; @@ -62,7 +62,7 @@ public void IsEmpty_BitmapContainsValues_ReturnsFalse(IRoaring32BitmapTestObject public void IsEmpty_EmptyBitmap_ReturnsTrue(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act var actual = testObject.ReadOnlyBitmap.IsEmpty; @@ -79,7 +79,7 @@ public class Min public void Min_BitmapContainsValues_ReturnsMinValue(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetForRange(start: 10, end: uint.MaxValue, count: 1000); + using IRoaring32BitmapTestObject testObject = factory.GetForRange(start: 10, end: uint.MaxValue, count: 1000); // Act var actual = testObject.ReadOnlyBitmap.Min; @@ -93,7 +93,7 @@ public void Min_BitmapContainsValues_ReturnsMinValue(IRoaring32BitmapTestObjectF public void Min_EmptyBitmap_ReturnsNull(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act uint? actual = testObject.ReadOnlyBitmap.Min; @@ -110,7 +110,7 @@ public class Max public void Max_BitmapContainsValues_ReturnsMaxValue(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetForRange(start: 0, end: 1001, count: 1001); + using IRoaring32BitmapTestObject testObject = factory.GetForRange(start: 0, end: 1001, count: 1001); // Act var actual = testObject.ReadOnlyBitmap.Max; @@ -124,7 +124,7 @@ public void Max_BitmapContainsValues_ReturnsMaxValue(IRoaring32BitmapTestObjectF public void Max_EmptyBitmap_ReturnsNull(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act uint? actual = testObject.ReadOnlyBitmap.Max; diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/NotTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/NotTests.cs index 04a5cee..6262a27 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/NotTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/NotTests.cs @@ -14,11 +14,11 @@ public class Not_ForWholeBitmap public void Not_EmptyBitmap_NegatesValuesInBitmap(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); - + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); + // Act - using var actual = testObject.ReadOnlyBitmap.Not(); - + using Roaring32Bitmap actual = testObject.ReadOnlyBitmap.Not(); + // Assert Assert.All([uint.MinValue, 1U, 2U, 1000U, uint.MaxValue], value => { @@ -27,23 +27,23 @@ public void Not_EmptyBitmap_NegatesValuesInBitmap(IRoaring32BitmapTestObjectFact Assert.Equal(0U, testObject.ReadOnlyBitmap.And(actual).Count); Assert.Equal(uint.MaxValue + 1UL, actual.Count); } - + [Theory] [InlineTestObject] public void Not_NotEmptyBitmap_NegatesValuesInBitmap(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues([0, 3, uint.MaxValue]); - + using IRoaring32BitmapTestObject testObject = factory.GetFromValues([0, 3, uint.MaxValue]); + // Act - using var actual = testObject.ReadOnlyBitmap.Not(); - + using Roaring32Bitmap actual = testObject.ReadOnlyBitmap.Not(); + // Assert Assert.All(testObject.Values, value => { Assert.False(actual.Contains(value)); }); - + Assert.All([1U, 2U, 1000U], value => { Assert.True(actual.Contains(value)); @@ -52,18 +52,18 @@ public void Not_NotEmptyBitmap_NegatesValuesInBitmap(IRoaring32BitmapTestObjectF Assert.Equal(uint.MaxValue - 2UL, actual.Count); } } - + public class INot_ForWholeBitmap { [Fact] public void INot_EmptyBitmap_NegatesValuesInBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); - + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + // Act testObject.Bitmap.INot(); - + // Assert Assert.All([uint.MinValue, 1U, 2U, 1000U, uint.MaxValue], value => { @@ -71,16 +71,16 @@ public void INot_EmptyBitmap_NegatesValuesInBitmap() }); Assert.Equal(uint.MaxValue + 1UL, testObject.Bitmap.Count); } - + [Fact] public void INot_NotEmptyBitmap_NegatesValuesInBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues([0, 3, uint.MaxValue]); - + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues([0, 3, uint.MaxValue]); + // Act testObject.Bitmap.INot(); - + // Assert Assert.All(testObject.Values, value => { @@ -93,7 +93,7 @@ public void INot_NotEmptyBitmap_NegatesValuesInBitmap() Assert.Equal(uint.MaxValue - 2UL, testObject.Bitmap.Count); } } - + public class NotRange { [Theory] @@ -102,22 +102,22 @@ public class NotRange public void NotRange_ArgumentsOutOfAllowedRange_ThrowsArgumentOutOfRangeException(uint start, uint end, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act && Assert Assert.Throws(() => testObject.ReadOnlyBitmap.NotRange(start, end)); } - + [Theory] [InlineTestObject] public void NotRange_EmptyBitmap_NegatesValuesInBitmap(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); - + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); + // Act - using var actual = testObject.ReadOnlyBitmap.NotRange(0, 3); - + using Roaring32Bitmap actual = testObject.ReadOnlyBitmap.NotRange(0, 3); + // Assert Assert.All([0U, 1U, 2U, 3U], value => { @@ -131,17 +131,17 @@ public void NotRange_EmptyBitmap_NegatesValuesInBitmap(IRoaring32BitmapTestObjec } public static IEnumerable TestData() => RangeTestData(); - + [Theory] [MemberData(nameof(TestData))] public void NotRange_NotEmptyBitmap_NegatesValuesInBitmap(uint[] values, uint start, uint end, uint[] expectedContains, uint[] expectedNotContains) { // Arrange using var bitmap = new Roaring32Bitmap(values); - + // Act - using var actual = bitmap.NotRange(start, end); - + using Roaring32Bitmap actual = bitmap.NotRange(start, end); + // Assert Assert.All(expectedContains, value => { @@ -153,7 +153,7 @@ public void NotRange_NotEmptyBitmap_NegatesValuesInBitmap(uint[] values, uint st }); } } - + public class INotRange { [Theory] @@ -167,16 +167,16 @@ public void INotRange_ArgumentsOutOfAllowedRange_ThrowsArgumentOutOfRangeExcepti // Act && Assert Assert.Throws(() => bitmap.INotRange(start, end)); } - + [Fact] public void INotRange_EmptyBitmap_NegatesValuesInBitmap() { // Arrange using var bitmap = new Roaring32Bitmap(); - + // Act bitmap.INotRange(0, 3); - + // Assert Assert.All([0U, 1U, 2U, 3U], value => { @@ -188,19 +188,19 @@ public void INotRange_EmptyBitmap_NegatesValuesInBitmap() }); Assert.Equal(4UL, bitmap.Count); } - + public static IEnumerable TestData() => RangeTestData(); - + [Theory] [MemberData(nameof(TestData))] public void INotRange_NotEmptyBitmap_NegatesValuesInBitmap(uint[] values, uint start, uint end, uint[] expectedContains, uint[] expectedNotContains) { // Arrange using var bitmap = new Roaring32Bitmap(values); - + // Act bitmap.INotRange(start, end); - + // Assert Assert.All(expectedContains, value => { @@ -212,15 +212,15 @@ public void INotRange_NotEmptyBitmap_NegatesValuesInBitmap(uint[] values, uint s }); } } - + private static IEnumerable RangeTestData() { yield return [new uint[] { 0, 1, 2, 3, 4 }, 0, 0, new uint[] { 1, 2, 3, 4 }, new uint[] { 0 }]; - yield return [new uint[] { 0, 1, 2, 3, 4 }, 0, 4, new uint[] { }, new uint[] { 0, 1, 2, 3, 4, 5}]; + yield return [new uint[] { 0, 1, 2, 3, 4 }, 0, 4, new uint[] { }, new uint[] { 0, 1, 2, 3, 4, 5 }]; yield return [new uint[] { 0, 2, 4, 6, 8 }, 2, 4, new uint[] { 0, 3, 6, 8 }, new uint[] { 1, 2, 4, 5, 7, 9 }]; - yield return [new uint[] { 0, 2, 4, 6, 8 }, 6, 10, new uint[] { 0, 2, 4, 7, 9, 10 }, new uint[] { 6, 8, 11 }]; - yield return [new uint[] { 0, 1, 2, 3, 4 }, 4, uint.MaxValue, new uint[] { 0, 1, 2, 3, 5, 6, uint.MaxValue }, new uint[] { 4 }]; - yield return [new uint[] { 0, 1, 2, 3, 4, uint.MaxValue }, uint.MinValue, uint.MaxValue, new uint[] { 5, 6, 7 }, new uint[] { 0, 1, 2, 3,4, uint.MaxValue }]; - yield return [new uint[] { uint.MaxValue - 2, uint.MaxValue }, uint.MinValue, uint.MaxValue, new uint[] { uint.MaxValue - 1 }, new uint[] { uint.MaxValue - 2, uint.MaxValue }]; + yield return [new uint[] { 0, 2, 4, 6, 8 }, 6, 10, new uint[] { 0, 2, 4, 7, 9, 10 }, new uint[] { 6, 8, 11 }]; + yield return [new uint[] { 0, 1, 2, 3, 4 }, 4, uint.MaxValue, new uint[] { 0, 1, 2, 3, 5, 6, uint.MaxValue }, new uint[] { 4 }]; + yield return [new uint[] { 0, 1, 2, 3, 4, uint.MaxValue }, uint.MinValue, uint.MaxValue, new uint[] { 5, 6, 7 }, new uint[] { 0, 1, 2, 3, 4, uint.MaxValue }]; + yield return [new uint[] { uint.MaxValue - 2, uint.MaxValue }, uint.MinValue, uint.MaxValue, new uint[] { uint.MaxValue - 1 }, new uint[] { uint.MaxValue - 2, uint.MaxValue }]; } } \ No newline at end of file diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/OrTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/OrTests.cs index 06c3cdb..4b34979 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/OrTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/OrTests.cs @@ -1,4 +1,5 @@ using System.Linq; +using Roaring.Net.CRoaring; using Xunit; namespace Roaring.Net.Tests.CRoaring.Roaring32BitmapTests; @@ -8,170 +9,170 @@ public class OrTests public class Or { [Theory] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] - public void Or_BitmapsWithDifferentValues_ReturnsUnionOfBitmaps(uint[] values1, uint[] values2, + [InlineMatrixTestObject(new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] + public void Or_BitmapsWithDifferentValues_ReturnsUnionOfBitmaps(uint[] values1, uint[] values2, TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues(values1); - using var testObject2 = matrix.Y.GetFromValues(values2); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues(values1); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues(values2); + // Act - using var actual = testObject1.ReadOnlyBitmap.Or(testObject2.Bitmap); - + using Roaring32Bitmap actual = testObject1.ReadOnlyBitmap.Or(testObject2.Bitmap); + // Assert Assert.Equal(values1.Union(values2), actual.Values); } } - + public class OrCount { [Theory] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] - public void Or_BitmapsWithDifferentValues_ReturnsCountAfterUnionOfBitmaps(uint[] values1, uint[] values2, + [InlineMatrixTestObject(new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] + public void Or_BitmapsWithDifferentValues_ReturnsCountAfterUnionOfBitmaps(uint[] values1, uint[] values2, TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues(values1); - using var testObject2 = matrix.Y.GetFromValues(values2); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues(values1); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues(values2); + // Act var actual = testObject1.ReadOnlyBitmap.OrCount(testObject2.Bitmap); - + // Assert Assert.Equal((ulong)values1.Union(values2).Count(), actual); } } - + public class OrMany { [Theory] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ 1 }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ 1 }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue }, new uint[]{ 3, 5 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue }, new uint[]{ 5, uint.MaxValue })] - public void OrMany_BitmapsWithDifferentValues_ReturnsUnionOfBitmaps(uint[] values1, uint[] values2, uint[] values3, + [InlineMatrixTestObject(new uint[] { }, new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { 1 }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { 1 }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue }, new uint[] { 3, 5 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue }, new uint[] { 5, uint.MaxValue })] + public void OrMany_BitmapsWithDifferentValues_ReturnsUnionOfBitmaps(uint[] values1, uint[] values2, uint[] values3, TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues(values1); - using var testObject2 = matrix.Y.GetFromValues(values2); - using var testObject3 = matrix.Z.GetFromValues(values3); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues(values1); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues(values2); + using IRoaring32BitmapTestObject testObject3 = matrix.Z.GetFromValues(values3); + // Act - var actual = testObject1.ReadOnlyBitmap.OrMany([testObject2.Bitmap, testObject3.Bitmap]); - + Roaring32Bitmap actual = testObject1.ReadOnlyBitmap.OrMany([testObject2.Bitmap, testObject3.Bitmap]); + // Assert Assert.Equal(values1.Union(values2).Union(values3).Order(), actual.Values); } } - + public class OrManyHeap { [Theory] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ 1 }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ 1 }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue }, new uint[]{ 3, 5 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue }, new uint[]{ 5, uint.MaxValue })] - public void OrManyHeap_BitmapsWithDifferentValues_ReturnsUnionOfBitmaps(uint[] values1, uint[] values2, uint[] values3, + [InlineMatrixTestObject(new uint[] { }, new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { 1 }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { 1 }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue }, new uint[] { 3, 5 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue }, new uint[] { 5, uint.MaxValue })] + public void OrManyHeap_BitmapsWithDifferentValues_ReturnsUnionOfBitmaps(uint[] values1, uint[] values2, uint[] values3, TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues(values1); - using var testObject2 = matrix.Y.GetFromValues(values2); - using var testObject3 = matrix.Z.GetFromValues(values3); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues(values1); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues(values2); + using IRoaring32BitmapTestObject testObject3 = matrix.Z.GetFromValues(values3); + // Act - var actual = testObject1.ReadOnlyBitmap.OrManyHeap([testObject2.Bitmap, testObject3.Bitmap]); - + Roaring32Bitmap actual = testObject1.ReadOnlyBitmap.OrManyHeap([testObject2.Bitmap, testObject3.Bitmap]); + // Assert Assert.Equal(values1.Union(values2).Union(values3).Order(), actual.Values); } } - + public class IOr { [Theory] - [InlineData(new uint[]{ }, new uint[]{ })] - [InlineData(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineData(new uint[]{ 1 }, new uint[]{ })] - [InlineData(new uint[]{ }, new uint[]{ 1 })] - [InlineData(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineData(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] + [InlineData(new uint[] { }, new uint[] { })] + [InlineData(new uint[] { 1 }, new uint[] { 1 })] + [InlineData(new uint[] { 1 }, new uint[] { })] + [InlineData(new uint[] { }, new uint[] { 1 })] + [InlineData(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineData(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] public void IOr_BitmapsWithDifferentValues_ReturnsUnionOfBitmaps(uint[] values1, uint[] values2) { // Arrange - using var testObject1 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values1); - using var testObject2 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values2); - + using Roaring32BitmapTestObject testObject1 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values1); + using Roaring32BitmapTestObject testObject2 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values2); + // Act testObject1.Bitmap.IOr(testObject2.Bitmap); - + // Assert Assert.Equal(values1.Union(values2), testObject1.Bitmap.Values); } } - + public class LazyOr { [Theory] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] - public void LazyOr_BitmapsWithDifferentValues_ReturnsUnionOfBitmaps(uint[] values1, uint[] values2, + [InlineMatrixTestObject(new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] + public void LazyOr_BitmapsWithDifferentValues_ReturnsUnionOfBitmaps(uint[] values1, uint[] values2, TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues(values1); - using var testObject2 = matrix.Y.GetFromValues(values2); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues(values1); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues(values2); + // Act - using var actual = testObject1.ReadOnlyBitmap.LazyOr(testObject2.Bitmap, true); + using Roaring32Bitmap actual = testObject1.ReadOnlyBitmap.LazyOr(testObject2.Bitmap, true); actual.RepairAfterLazy(); - + // Assert Assert.Equal(values1.Union(values2), actual.Values); } } - + public class ILazyOr { [Theory] - [InlineData(new uint[]{ }, new uint[]{ })] - [InlineData(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineData(new uint[]{ 1 }, new uint[]{ })] - [InlineData(new uint[]{ }, new uint[]{ 1 })] - [InlineData(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineData(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] + [InlineData(new uint[] { }, new uint[] { })] + [InlineData(new uint[] { 1 }, new uint[] { 1 })] + [InlineData(new uint[] { 1 }, new uint[] { })] + [InlineData(new uint[] { }, new uint[] { 1 })] + [InlineData(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineData(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] public void IOr_BitmapsWithDifferentValues_ReturnsUnionOfBitmaps(uint[] values1, uint[] values2) { // Arrange - using var testObject1 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values1); - using var testObject2 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values2); - + using Roaring32BitmapTestObject testObject1 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values1); + using Roaring32BitmapTestObject testObject2 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values2); + // Act testObject1.Bitmap.ILazyOr(testObject2.Bitmap, true); testObject1.Bitmap.RepairAfterLazy(); - + // Assert Assert.Equal(values1.Union(values2), testObject1.Bitmap.Values); } diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/RemoveTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/RemoveTests.cs index 9ca5a1f..5f2ae32 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/RemoveTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/RemoveTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using Xunit; @@ -15,7 +16,7 @@ public class Remove public void Remove_BitmapIsEmpty_DoesNotRemoveValue() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); // Act testObject.Bitmap.Remove(uint.MaxValue); @@ -28,7 +29,7 @@ public void Remove_BitmapIsEmpty_DoesNotRemoveValue() public void Remove_BitmapWithValue_RemovesValueFromBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); var removedValue = testObject.Values.First(); // Act @@ -48,7 +49,7 @@ public class RemoveMany public void RemoveMany_BitmapIsEmpty_DoesNotRemoveAnyValue() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); // Act testObject.Bitmap.RemoveMany([1, 10, uint.MaxValue]); @@ -61,7 +62,7 @@ public void RemoveMany_BitmapIsEmpty_DoesNotRemoveAnyValue() public void RemoveMany_BitmapWithValues_RemovesValuesFromBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); testObject.Bitmap.Add(uint.MaxValue); var removedValues = testObject.Values.Take(10).Append(uint.MaxValue).ToArray(); @@ -88,7 +89,7 @@ public class RemoveMany_WithOffset public void RemoveMany_WithCorrectOffsetAndCount_RemovesValuesFromBitmap(uint[] values, uint offset, uint count) { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values); // Act testObject.Bitmap.RemoveMany(values, offset, count); @@ -106,7 +107,7 @@ public void RemoveMany_OffsetAndCountOutOfAllowedRange_ThrowsArgumentOutOfRangeE uint offset, uint count) { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values); // Act && Assert Assert.Throws(() => { testObject.Bitmap.RemoveMany(values, offset, count); }); @@ -119,7 +120,7 @@ public class TryRemove public void TryRemove_BitmapIsEmpty_DoesNotRemoveValueAndReturnsFalse() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); // Act var actual = testObject.Bitmap.TryRemove(uint.MaxValue); @@ -133,7 +134,7 @@ public void TryRemove_BitmapIsEmpty_DoesNotRemoveValueAndReturnsFalse() public void TryRemove_BitmapWithValue_RemovesValueFromBitmapAndReturnsTrue() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); var removedValue = testObject.Values.First(); // Act @@ -156,7 +157,7 @@ public class RemoveRange public void RemoveRange_ArgumentsOutOfAllowedRange_ThrowsArgumentOutOfRangeException(uint start, uint end) { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); // Act && Assert Assert.Throws(() => testObject.Bitmap.RemoveRange(start, end)); @@ -177,7 +178,7 @@ public void RemoveRange_ArgumentsOutOfAllowedRange_ThrowsArgumentOutOfRangeExcep public void RemoveRange_CorrectRange_BitmapRemovesRange(uint startTest, uint endTest, uint start, uint end) { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetForRange(startTest, endTest); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetForRange(startTest, endTest); // Act testObject.Bitmap.RemoveRange(start, end); @@ -186,7 +187,7 @@ public void RemoveRange_CorrectRange_BitmapRemovesRange(uint startTest, uint end var removedValues = Enumerable.Range((int)start, (int)(end - start + 1)) // 0..10 .Select(x => (uint)x) .ToList(); - var expected = testObject.Values.Except(removedValues); + IEnumerable expected = testObject.Values.Except(removedValues); var actual = testObject.Bitmap.Values.ToList(); Assert.Equal(expected, actual); @@ -199,7 +200,7 @@ public class Clear public void Clear_BitmapIsEmpty_DoesNotRemoveValues() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetEmpty(); // Act testObject.Bitmap.Clear(); @@ -212,7 +213,7 @@ public void Clear_BitmapIsEmpty_DoesNotRemoveValues() public void Clear_BitmapHasValues_RemovesAllValuesFromBitmap() { // Arrange - using var testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); + using Roaring32BitmapTestObject testObject = Roaring32BitmapTestObjectFactory.Default.GetDefault(); // Act testObject.Bitmap.Clear(); diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/Roaring32BitmapTestObject.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/Roaring32BitmapTestObject.cs index 9b1c255..fbc8540 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/Roaring32BitmapTestObject.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/Roaring32BitmapTestObject.cs @@ -8,13 +8,13 @@ internal sealed class Roaring32BitmapTestObject : IRoaring32BitmapTestObject Roaring32BitmapBase IRoaring32BitmapTestObject.Bitmap => Bitmap; public Roaring32Bitmap Bitmap { get; } public uint[] Values { get; } - + public Roaring32BitmapTestObject(Roaring32Bitmap bitmap, uint[] values) { Bitmap = bitmap; Values = values; } - + public void Dispose() { Bitmap.Dispose(); diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/Roaring32BitmapTestObjectFactory.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/Roaring32BitmapTestObjectFactory.cs index b6454e4..a6566cb 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/Roaring32BitmapTestObjectFactory.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/Roaring32BitmapTestObjectFactory.cs @@ -5,7 +5,7 @@ namespace Roaring.Net.Tests.CRoaring.Roaring32BitmapTests; internal class Roaring32BitmapTestObjectFactory : Roaring32BitmapTestObjectFactoryBase { public static Roaring32BitmapTestObjectFactory Default { get; } = new(); - + protected override Roaring32BitmapTestObject CreateBitmapObject(Roaring32Bitmap bitmap, uint[] values) { return new Roaring32BitmapTestObject(bitmap, values); diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/SerializationTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/SerializationTests.cs index 48f6b2d..36c041a 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/SerializationTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/SerializationTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using Roaring.Net.CRoaring; using Roaring.Net.Tests.CRoaring.TestData; @@ -16,7 +15,7 @@ public class GetSerializationBytes public void GetSerializationBytes_NotSupportedSerializationFormat_ThrowsArgumentOutOfRangeException(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act && Assert Assert.Throws(() => @@ -24,7 +23,7 @@ public void GetSerializationBytes_NotSupportedSerializationFormat_ThrowsArgument testObject.ReadOnlyBitmap.GetSerializationBytes((SerializationFormat)int.MaxValue); }); } - + [Theory] [InlineTestObject(SerializationFormat.Normal, 5)] [InlineTestObject(SerializationFormat.Portable, 8)] @@ -32,7 +31,7 @@ public void GetSerializationBytes_NotSupportedSerializationFormat_ThrowsArgument public void GetSerializationBytes_EmptyBitmap_ReturnsValueGreaterThanZero(SerializationFormat format, int size, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); // Act var actual = testObject.ReadOnlyBitmap.GetSerializationBytes(format); @@ -48,7 +47,7 @@ public void GetSerializationBytes_EmptyBitmap_ReturnsValueGreaterThanZero(Serial public void GetSerializationBytes_BitmapContainsValues_ReturnsValueGreaterThanZero(SerializationFormat format, int size, IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetDefault(); + using IRoaring32BitmapTestObject testObject = factory.GetDefault(); // Act var actual = testObject.ReadOnlyBitmap.GetSerializationBytes(format); @@ -57,7 +56,7 @@ public void GetSerializationBytes_BitmapContainsValues_ReturnsValueGreaterThanZe Assert.Equal((nuint)size, actual); } } - + public class Serialize { [Theory] @@ -65,13 +64,13 @@ public class Serialize public void Serialize_NotSupportedSerializationFormat_ThrowsArgumentOutOfRangeException(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(SerializationTestBitmap.GetTestBitmapValues().ToArray()); + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(SerializationTestBitmap.GetTestBitmapValues().ToArray()); // Act && Assert Assert.Throws(() => testObject.ReadOnlyBitmap.Serialize((SerializationFormat)int.MaxValue)); } } - + public class SerializeNormal { [Theory] @@ -79,7 +78,7 @@ public class SerializeNormal public void Serialize_Deserialize_SelfTest_EqualsToDeserialized(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(SerializationTestBitmap.GetTestBitmapValues().ToArray()); + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(SerializationTestBitmap.GetTestBitmapValues().ToArray()); // Act var serializedBitmap = testObject.ReadOnlyBitmap.Serialize(SerializationFormat.Normal); @@ -88,12 +87,12 @@ public void Serialize_Deserialize_SelfTest_EqualsToDeserialized(IRoaring32Bitmap using var deserializedBitmap = Roaring32Bitmap.Deserialize(serializedBitmap, SerializationFormat.Normal); Assert.Equal(testObject.ReadOnlyBitmap.Values, deserializedBitmap.Values); } - + [Fact] public void Serialize_Deserialize_SelfTestWithOptimize_EqualsToDeserialized() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); // Act bitmap.Optimize(); @@ -103,13 +102,13 @@ public void Serialize_Deserialize_SelfTestWithOptimize_EqualsToDeserialized() using var deserializedBitmap = Roaring32Bitmap.Deserialize(serializedBitmap, SerializationFormat.Normal); Assert.Equal(bitmap.Values, deserializedBitmap.Values); } - + [Theory] [InlineTestObject] public void Serialize_DeserializeUnsafe_SelfTest_EqualsToDeserialized(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(SerializationTestBitmap.GetTestBitmapValues().ToArray()); + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(SerializationTestBitmap.GetTestBitmapValues().ToArray()); // Act var serializedBitmap = testObject.ReadOnlyBitmap.Serialize(SerializationFormat.Normal); @@ -118,12 +117,12 @@ public void Serialize_DeserializeUnsafe_SelfTest_EqualsToDeserialized(IRoaring32 using var deserializedBitmap = Roaring32Bitmap.DeserializeUnsafe(serializedBitmap, SerializationFormat.Normal); Assert.Equal(testObject.ReadOnlyBitmap.Values, deserializedBitmap.Values); } - + [Fact] public void Serialize_DeserializeUnsafe_SelfTestWithOptimize_EqualsToDeserialized() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); // Act bitmap.Optimize(); @@ -134,7 +133,7 @@ public void Serialize_DeserializeUnsafe_SelfTestWithOptimize_EqualsToDeserialize Assert.Equal(bitmap.Values, deserializedBitmap.Values); } } - + public class SerializePortable { [Theory] @@ -142,7 +141,7 @@ public class SerializePortable public void Serialize_TestBitmap_EqualsToBitmapFromJava(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(SerializationTestBitmap.GetTestBitmapValues().ToArray()); + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(SerializationTestBitmap.GetTestBitmapValues().ToArray()); // Act var serializedBitmap = testObject.ReadOnlyBitmap.Serialize(SerializationFormat.Portable); @@ -151,13 +150,13 @@ public void Serialize_TestBitmap_EqualsToBitmapFromJava(IRoaring32BitmapTestObje var testData = File.ReadAllBytes($"{nameof(CRoaring)}/TestData/bitmapwithoutruns.bin"); Assert.Equal(testData, serializedBitmap); } - + [Theory] [InlineTestObject] public void Serialize_Deserialize_SelfTest_EqualsToDeserialized(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(SerializationTestBitmap.GetTestBitmapValues().ToArray()); + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(SerializationTestBitmap.GetTestBitmapValues().ToArray()); // Act var serializedBitmap = testObject.ReadOnlyBitmap.Serialize(SerializationFormat.Portable); @@ -166,13 +165,13 @@ public void Serialize_Deserialize_SelfTest_EqualsToDeserialized(IRoaring32Bitmap using var deserializedBitmap = Roaring32Bitmap.Deserialize(serializedBitmap, SerializationFormat.Portable); Assert.Equal(testObject.ReadOnlyBitmap.Values, deserializedBitmap.Values); } - + [Theory] [InlineTestObject] public void Serialize_DeserializeUnsafe_SelfTest_EqualsToDeserialized(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetFromValues(SerializationTestBitmap.GetTestBitmapValues().ToArray()); + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(SerializationTestBitmap.GetTestBitmapValues().ToArray()); // Act var serializedBitmap = testObject.ReadOnlyBitmap.Serialize(SerializationFormat.Portable); @@ -181,12 +180,12 @@ public void Serialize_DeserializeUnsafe_SelfTest_EqualsToDeserialized(IRoaring32 using var deserializedBitmap = Roaring32Bitmap.DeserializeUnsafe(serializedBitmap, SerializationFormat.Portable); Assert.Equal(testObject.ReadOnlyBitmap.Values, deserializedBitmap.Values); } - + [Fact] public void Serialize_TestBitmapWithOptimize_EqualsToBitmapFromJava() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); // Act bitmap.Optimize(); @@ -196,12 +195,12 @@ public void Serialize_TestBitmapWithOptimize_EqualsToBitmapFromJava() var testData = File.ReadAllBytes($"{nameof(CRoaring)}/TestData/bitmapwithruns.bin"); Assert.Equal(testData, serializedBitmap); } - + [Fact] public void Serialize_Deserialize_SelfTestWithOptimize_EqualsToDeserialized() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); // Act bitmap.Optimize(); @@ -211,12 +210,12 @@ public void Serialize_Deserialize_SelfTestWithOptimize_EqualsToDeserialized() using var deserializedBitmap = Roaring32Bitmap.Deserialize(serializedBitmap, SerializationFormat.Portable); Assert.Equal(bitmap.Values, deserializedBitmap.Values); } - + [Fact] public void Serialize_DeserializeUnsafe_SelfTestWithOptimize_EqualsToDeserialized() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); // Act bitmap.Optimize(); @@ -227,8 +226,8 @@ public void Serialize_DeserializeUnsafe_SelfTestWithOptimize_EqualsToDeserialize Assert.Equal(bitmap.Values, deserializedBitmap.Values); } } - - + + public class Deserialize { [Fact] @@ -238,7 +237,7 @@ public void Deserialize_NotSupportedSerializationFormat_ThrowsArgumentOutOfRange Assert.Throws(() => Roaring32Bitmap.Deserialize([], (SerializationFormat)int.MaxValue)); } } - + public class DeserializeNormal { [Fact] @@ -248,7 +247,7 @@ public void Deserialize_InvalidDataCannotDeserialize_ThrowsInvalidOperationExcep Assert.Throws(() => Roaring32Bitmap.Deserialize([])); } } - + public class DeserializeUnsafe { [Fact] @@ -268,16 +267,16 @@ public void DeserializeUnsafe_InvalidDataCannotDeserialize_ThrowsInvalidOperatio Assert.Throws(() => Roaring32Bitmap.DeserializeUnsafe([])); } } - + public class DeserializePortable { [Fact] public void Deserialize_DeserializesBitmapFromJava() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var testData = File.ReadAllBytes($"{nameof(CRoaring)}/TestData/bitmapwithoutruns.bin"); - + // Act var deserializedBitmap = Roaring32Bitmap.Deserialize(testData, SerializationFormat.Portable); @@ -289,7 +288,7 @@ public void Deserialize_DeserializesBitmapFromJava() public void Deserialize_WithOptimize_DeserializesBitmapFromJava() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var testData = File.ReadAllBytes($"{nameof(CRoaring)}/TestData/bitmapwithruns.bin"); // Act @@ -298,7 +297,7 @@ public void Deserialize_WithOptimize_DeserializesBitmapFromJava() // Assert Assert.Equal(bitmap.AndCount(deserializedBitmap), bitmap.Count); } - + [Fact] public void DeserializeAndInvalidDataCannotDeserialize_ThrowsInvalidOperationException() { @@ -306,16 +305,16 @@ public void DeserializeAndInvalidDataCannotDeserialize_ThrowsInvalidOperationExc Assert.Throws(() => Roaring32Bitmap.Deserialize([], SerializationFormat.Portable)); } } - + public class DeserializeUnsafePortable { [Fact] public void DeserializeUnsafe_DeserializesBitmapFromJava() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var testData = File.ReadAllBytes($"{nameof(CRoaring)}/TestData/bitmapwithoutruns.bin"); - + // Act var deserializedBitmap = Roaring32Bitmap.DeserializeUnsafe(testData, SerializationFormat.Portable); @@ -327,7 +326,7 @@ public void DeserializeUnsafe_DeserializesBitmapFromJava() public void DeserializeUnsafe_WithOptimize_DeserializesBitmapFromJava() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var testData = File.ReadAllBytes($"{nameof(CRoaring)}/TestData/bitmapwithruns.bin"); // Act @@ -336,7 +335,7 @@ public void DeserializeUnsafe_WithOptimize_DeserializesBitmapFromJava() // Assert Assert.Equal(bitmap.AndCount(deserializedBitmap), bitmap.Count); } - + [Fact] public void DeserializeUnsafe_InvalidDataCannotDeserialize_ThrowsInvalidOperationException() { @@ -344,7 +343,7 @@ public void DeserializeUnsafe_InvalidDataCannotDeserialize_ThrowsInvalidOperatio Assert.Throws(() => Roaring32Bitmap.DeserializeUnsafe([], SerializationFormat.Portable)); } } - + public class GetSerializedSize { [Theory] @@ -355,25 +354,25 @@ public void GetSerializedSize_NotSupportedSerializationFormat_ThrowsArgumentOutO // Act && Assert Assert.Throws(() => Roaring32Bitmap.GetSerializedSize([], 10, serializationFormat)); } - + [Fact] public void GetSerializedSize_Portable_InvalidDataCannotDeserialize_ReturnsZero() { // Act var actual = Roaring32Bitmap.GetSerializedSize([1, 2, 3], uint.MaxValue); - + // Assert Assert.Equal(0U, actual); } - + [Fact] public void GetSerializedSize_Portable_ReturnsNumberOfBytesOfSerializedBitmapInBuffer() { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var testData = File.ReadAllBytes($"{nameof(CRoaring)}/TestData/bitmapwithoutruns.bin"); Array.Resize(ref testData, testData.Length + 100); - + // Act var actual = Roaring32Bitmap.GetSerializedSize(testData, (nuint)testData.Length); diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/StatisticsTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/StatisticsTests.cs index 11e09b1..4e73c2a 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/StatisticsTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/StatisticsTests.cs @@ -12,40 +12,40 @@ public void GetStatistics_ForTestData_ReturnsCount(IRoaring32BitmapTestObjectFac { // Arrange uint[] values = [1, 2, 3, 4, 6, 7, 999991, 999992, 999993, 999994, 999996, 999997]; - using var testObject = factory.GetFromValues(values); - + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(values); + // Act - var actual = testObject.ReadOnlyBitmap.GetStatistics(); + Statistics actual = testObject.ReadOnlyBitmap.GetStatistics(); // Assert Assert.Equal((ulong)values.Length, actual.Count); } - + [Theory] [InlineTestObject] public void GetStatistics_ForTestData_ReturnsMinMax(IRoaring32BitmapTestObjectFactory factory) { // Arrange uint[] values = [1, 2, 3, 4, 6, 7, 999991, 999992, 999993, 999994, 999996, 999997]; - using var testObject = factory.GetFromValues(values); - + using IRoaring32BitmapTestObject testObject = factory.GetFromValues(values); + // Act - var actual = testObject.ReadOnlyBitmap.GetStatistics(); + Statistics actual = testObject.ReadOnlyBitmap.GetStatistics(); // Assert Assert.Equal(1U, actual.MinValue); Assert.Equal(999997U, actual.MaxValue); } - + [Theory] [InlineTestObject] public void GetStatistics_ForEmpty_ReturnsZeroForContainerCount(IRoaring32BitmapTestObjectFactory factory) { // Arrange - using var testObject = factory.GetEmpty(); - + using IRoaring32BitmapTestObject testObject = factory.GetEmpty(); + // Act - var actual = testObject.ReadOnlyBitmap.GetStatistics(); + Statistics actual = testObject.ReadOnlyBitmap.GetStatistics(); // Assert Assert.Equal(0U, actual.ContainerCount); @@ -53,17 +53,17 @@ public void GetStatistics_ForEmpty_ReturnsZeroForContainerCount(IRoaring32Bitmap Assert.Equal(0U, actual.RunContainerCount); Assert.Equal(0U, actual.BitsetContainerCount); } - + [Fact] public void GetStatistics_ForArrayContainerTestData_ReturnsContainerCount() { // Arrange uint[] values = [1, 3, 4, 7, 999991, 999992, 999994, 999997]; using var bitmap = new Roaring32Bitmap(values); - + // Act bitmap.Optimize(); - var actual = bitmap.GetStatistics(); + Statistics actual = bitmap.GetStatistics(); // Assert Assert.Equal(2U, actual.ContainerCount); @@ -71,139 +71,139 @@ public void GetStatistics_ForArrayContainerTestData_ReturnsContainerCount() Assert.Equal(0U, actual.RunContainerCount); Assert.Equal(0U, actual.BitsetContainerCount); } - + [Fact] public void GetStatistics_ForBitsetContainerTestData_ReturnsContainerCount() { // Arrange using var bitmap = new Roaring32Bitmap(); - bitmap.AddMany(Enumerable.Range(0, 65536).Select(x=> (uint)x * 2).ToArray()); - + bitmap.AddMany(Enumerable.Range(0, 65536).Select(x => (uint)x * 2).ToArray()); + // Act bitmap.Optimize(); - var actual = bitmap.GetStatistics(); - + Statistics actual = bitmap.GetStatistics(); + // Assert Assert.Equal(2U, actual.ContainerCount); Assert.Equal(0U, actual.ArrayContainerCount); Assert.Equal(0U, actual.RunContainerCount); Assert.Equal(2U, actual.BitsetContainerCount); } - + [Fact] public void GetStatistics_ForRunContainerTestData_ReturnsContainerCount() { // Arrange using var bitmap = new Roaring32Bitmap(); - bitmap.AddMany(Enumerable.Range(10, 1_000).Select(x=> (uint)x).ToArray()); - + bitmap.AddMany(Enumerable.Range(10, 1_000).Select(x => (uint)x).ToArray()); + // Act bitmap.Optimize(); - var actual = bitmap.GetStatistics(); - + Statistics actual = bitmap.GetStatistics(); + // Assert Assert.Equal(1U, actual.ContainerCount); Assert.Equal(0U, actual.ArrayContainerCount); Assert.Equal(1U, actual.RunContainerCount); Assert.Equal(0U, actual.BitsetContainerCount); } - + [Fact] public void GetStatistics_ForArrayContainerTestData_ReturnsContainerValuesCount() { // Arrange uint[] values = [1, 3, 4, 7, 999991, 999992, 999994, 999997]; using var bitmap = new Roaring32Bitmap(values); - + // Act bitmap.Optimize(); - var actual = bitmap.GetStatistics(); + Statistics actual = bitmap.GetStatistics(); // Assert Assert.Equal(8U, actual.ArrayContainerValuesCount); Assert.Equal(0U, actual.RunContainerValuesCount); Assert.Equal(0U, actual.BitsetContainerValuesCount); } - + [Fact] public void GetStatistics_ForBitsetContainerTestData_ReturnsContainerValuesCount() { // Arrange using var bitmap = new Roaring32Bitmap(); - bitmap.AddMany(Enumerable.Range(0, 65536).Select(x=> (uint)x * 2).ToArray()); - + bitmap.AddMany(Enumerable.Range(0, 65536).Select(x => (uint)x * 2).ToArray()); + // Act bitmap.Optimize(); - var actual = bitmap.GetStatistics(); - + Statistics actual = bitmap.GetStatistics(); + // Assert Assert.Equal(0U, actual.ArrayContainerValuesCount); Assert.Equal(0U, actual.RunContainerValuesCount); Assert.Equal(65536U, actual.BitsetContainerValuesCount); } - + [Fact] public void GetStatistics_ForRunContainerTestData_ReturnsContainerValuesCount() { // Arrange using var bitmap = new Roaring32Bitmap(); - bitmap.AddMany(Enumerable.Range(10, 1_000).Select(x=> (uint)x).ToArray()); - + bitmap.AddMany(Enumerable.Range(10, 1_000).Select(x => (uint)x).ToArray()); + // Act bitmap.Optimize(); - var actual = bitmap.GetStatistics(); - + Statistics actual = bitmap.GetStatistics(); + // Assert Assert.Equal(0U, actual.ArrayContainerValuesCount); Assert.Equal(1000U, actual.RunContainerValuesCount); Assert.Equal(0U, actual.BitsetContainerValuesCount); } - + [Fact] public void GetStatistics_ForArrayContainerTestData_ReturnsContainerBytes() { // Arrange uint[] values = [1, 3, 4, 7, 999991, 999992, 999994, 999997]; using var bitmap = new Roaring32Bitmap(values); - + // Act bitmap.Optimize(); - var actual = bitmap.GetStatistics(); + Statistics actual = bitmap.GetStatistics(); // Assert Assert.Equal(16U, actual.ArrayContainerBytes); Assert.Equal(0U, actual.RunContainerBytes); Assert.Equal(0U, actual.BitsetContainerBytes); } - + [Fact] public void GetStatistics_ForBitsetContainerTestData_ReturnsContainerBytes() { // Arrange using var bitmap = new Roaring32Bitmap(); - bitmap.AddMany(Enumerable.Range(0, 65536).Select(x=> (uint)x * 2).ToArray()); - + bitmap.AddMany(Enumerable.Range(0, 65536).Select(x => (uint)x * 2).ToArray()); + // Act bitmap.Optimize(); - var actual = bitmap.GetStatistics(); - + Statistics actual = bitmap.GetStatistics(); + // Assert Assert.Equal(0U, actual.ArrayContainerBytes); Assert.Equal(0U, actual.RunContainerBytes); Assert.Equal(16384U, actual.BitsetContainerBytes); } - + [Fact] public void GetStatistics_ForRunContainerTestData_ReturnsContainerBytes() { // Arrange using var bitmap = new Roaring32Bitmap(); - bitmap.AddMany(Enumerable.Range(10, 1_000).Select(x=> (uint)x).ToArray()); - + bitmap.AddMany(Enumerable.Range(10, 1_000).Select(x => (uint)x).ToArray()); + // Act bitmap.Optimize(); - var actual = bitmap.GetStatistics(); - + Statistics actual = bitmap.GetStatistics(); + // Assert Assert.Equal(0U, actual.ArrayContainerBytes); Assert.Equal(6U, actual.RunContainerBytes); diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/XorTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/XorTests.cs index b601799..046453d 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/XorTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32BitmapTests/XorTests.cs @@ -1,4 +1,6 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; +using Roaring.Net.CRoaring; using Xunit; namespace Roaring.Net.Tests.CRoaring.Roaring32BitmapTests; @@ -8,147 +10,148 @@ public class XorTests public class Xor { [Theory] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] - public void Xor_BitmapsWithDifferentValues_ReturnsSymmetricDifferenceOfBitmaps(uint[] values1, uint[] values2, + [InlineMatrixTestObject(new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] + public void Xor_BitmapsWithDifferentValues_ReturnsSymmetricDifferenceOfBitmaps(uint[] values1, uint[] values2, TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues(values1); - using var testObject2 = matrix.Y.GetFromValues(values2); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues(values1); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues(values2); + // Act - using var actual = testObject1.ReadOnlyBitmap.Xor(testObject2.Bitmap); - + using Roaring32Bitmap actual = testObject1.ReadOnlyBitmap.Xor(testObject2.Bitmap); + // Assert Assert.Equal(values1.Union(values2).Except(values1.Intersect(values2)), actual.Values); } } - + public class XorCount { [Theory] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] - public void XorCount_BitmapsWithDifferentValues_ReturnsSymmetricDifferenceOfBitmaps(uint[] values1, uint[] values2, + [InlineMatrixTestObject(new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] + public void XorCount_BitmapsWithDifferentValues_ReturnsSymmetricDifferenceOfBitmaps(uint[] values1, uint[] values2, TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues(values1); - using var testObject2 = matrix.Y.GetFromValues(values2); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues(values1); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues(values2); + // Act var actual = testObject1.ReadOnlyBitmap.XorCount(testObject2.Bitmap); - + // Assert Assert.Equal((uint)values1.Union(values2).Except(values1.Intersect(values2)).Count(), actual); } } - + public class IXor { [Theory] - [InlineData(new uint[]{ }, new uint[]{ })] - [InlineData(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineData(new uint[]{ 1 }, new uint[]{ })] - [InlineData(new uint[]{ }, new uint[]{ 1 })] - [InlineData(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineData(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] + [InlineData(new uint[] { }, new uint[] { })] + [InlineData(new uint[] { 1 }, new uint[] { 1 })] + [InlineData(new uint[] { 1 }, new uint[] { })] + [InlineData(new uint[] { }, new uint[] { 1 })] + [InlineData(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineData(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] public void IXor_BitmapsWithDifferentValues_ReturnsSymmetricDifferenceOfBitmaps(uint[] values1, uint[] values2) { // Arrange - using var testObject1 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values1); - using var testObject2 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values2); - + using Roaring32BitmapTestObject testObject1 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values1); + using Roaring32BitmapTestObject testObject2 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values2); + // Act testObject1.Bitmap.IXor(testObject2.Bitmap); - + // Assert Assert.Equal(values1.Union(values2).Except(values1.Intersect(values2)), testObject1.Bitmap.Values); } } - + public class XorMany { [Theory] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ 1 }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ 1 }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue }, new uint[]{ 3, 5 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue }, new uint[]{ 5, uint.MaxValue })] - public void XorMany_BitmapsWithDifferentValues_ReturnsSymmetricDifferenceOfBitmaps(uint[] values1, uint[] values2, uint[] values3, + [InlineMatrixTestObject(new uint[] { }, new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { 1 }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { 1 }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue }, new uint[] { 3, 5 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue }, new uint[] { 5, uint.MaxValue })] + public void XorMany_BitmapsWithDifferentValues_ReturnsSymmetricDifferenceOfBitmaps(uint[] values1, uint[] values2, uint[] values3, TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues(values1); - using var testObject2 = matrix.Y.GetFromValues(values2); - using var testObject3 = matrix.Z.GetFromValues(values3); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues(values1); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues(values2); + using IRoaring32BitmapTestObject testObject3 = matrix.Z.GetFromValues(values3); + // Act - var actual = testObject1.ReadOnlyBitmap.XorMany([testObject2.Bitmap, testObject3.Bitmap]); - + Roaring32Bitmap actual = testObject1.ReadOnlyBitmap.XorMany([testObject2.Bitmap, testObject3.Bitmap]); + // Assert var tempSet = values1.Union(values2).Except(values1.Intersect(values2)).ToList(); - var expectedSet = values3.Union(tempSet).Except(values3.Intersect(tempSet)); + IEnumerable expectedSet = values3.Union(tempSet).Except(values3.Intersect(tempSet)); Assert.Equal(expectedSet.Order(), actual.Values); } } - + public class LazyXor { [Theory] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 1 }, new uint[]{ })] - [InlineMatrixTestObject(new uint[]{ }, new uint[]{ 1 })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineMatrixTestObject(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] - public void Xor_BitmapsWithDifferentValues_ReturnsSymmetricDifferenceOfBitmaps(uint[] values1, uint[] values2, + [InlineMatrixTestObject(new uint[] { }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { 1 }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0x1 }, new uint[] { })] + [InlineMatrixTestObject(new uint[] { }, new uint[] { 1 })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineMatrixTestObject(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] + public void Xor_BitmapsWithDifferentValues_ReturnsSymmetricDifferenceOfBitmaps(uint[] values1, uint[] values2, TestObjectMatrix matrix) { // Arrange - using var testObject1 = matrix.X.GetFromValues(values1); - using var testObject2 = matrix.Y.GetFromValues(values2); - + using IRoaring32BitmapTestObject testObject1 = matrix.X.GetFromValues(values1); + using IRoaring32BitmapTestObject testObject2 = matrix.Y.GetFromValues(values2); + // Act - using var actual = testObject1.ReadOnlyBitmap.LazyXor(testObject2.Bitmap); + using Roaring32Bitmap actual = testObject1.ReadOnlyBitmap.LazyXor(testObject2.Bitmap); actual.RepairAfterLazy(); - + // Assert Assert.Equal(values1.Union(values2).Except(values1.Intersect(values2)), actual.Values); - } + } } + public class ILazyXor { [Theory] - [InlineData(new uint[]{ }, new uint[]{ })] - [InlineData(new uint[]{ 1 }, new uint[]{ 1 })] - [InlineData(new uint[]{ 1 }, new uint[]{ })] - [InlineData(new uint[]{ }, new uint[]{ 1 })] - [InlineData(new uint[]{ 0, 1, 2 }, new uint[]{ 1, uint.MaxValue })] - [InlineData(new uint[]{ 0, 1, 2, uint.MaxValue }, new uint[]{ 0, 2, uint.MaxValue })] + [InlineData(new uint[] { }, new uint[] { })] + [InlineData(new uint[] { 1 }, new uint[] { 1 })] + [InlineData(new uint[] { 1 }, new uint[] { })] + [InlineData(new uint[] { }, new uint[] { 1 })] + [InlineData(new uint[] { 0, 1, 2 }, new uint[] { 1, uint.MaxValue })] + [InlineData(new uint[] { 0, 1, 2, uint.MaxValue }, new uint[] { 0, 2, uint.MaxValue })] public void Xor_BitmapsWithDifferentValues_ReturnsSymmetricDifferenceOfBitmaps(uint[] values1, uint[] values2) { // Arrange - using var testObject1 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values1); - using var testObject2 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values2); - + using Roaring32BitmapTestObject testObject1 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values1); + using Roaring32BitmapTestObject testObject2 = Roaring32BitmapTestObjectFactory.Default.GetFromValues(values2); + // Act testObject1.Bitmap.ILazyXor(testObject2.Bitmap); testObject1.Bitmap.RepairAfterLazy(); - + // Assert Assert.Equal(values1.Union(values2).Except(values1.Intersect(values2)), testObject1.Bitmap.Values); - } + } } } \ No newline at end of file diff --git a/test/Roaring.Net.Tests/CRoaring/Roaring32EnumeratorTests/DisposeTests.cs b/test/Roaring.Net.Tests/CRoaring/Roaring32EnumeratorTests/DisposeTests.cs index 99c0cbe..9f31b3d 100644 --- a/test/Roaring.Net.Tests/CRoaring/Roaring32EnumeratorTests/DisposeTests.cs +++ b/test/Roaring.Net.Tests/CRoaring/Roaring32EnumeratorTests/DisposeTests.cs @@ -11,13 +11,13 @@ public class Finalizer { [Fact] public void Finalizer_InvokedMoreThanOnce_BlocksRedundantCalls() - { + { // Arrange - using var bitmap = SerializationTestBitmap.GetTestBitmap(); + using Roaring32Bitmap bitmap = SerializationTestBitmap.GetTestBitmap(); var enumerator = new Roaring32Enumerator(bitmap.Pointer); - - var finalizer = enumerator.GetType().GetMethod("Finalize", BindingFlags.Instance | BindingFlags.NonPublic); - + + MethodInfo? finalizer = enumerator.GetType().GetMethod("Finalize", BindingFlags.Instance | BindingFlags.NonPublic); + // Act && Assert Assert.NotNull(finalizer); finalizer.Invoke(enumerator, null); diff --git a/test/Roaring.Net.Tests/CRoaring/TestData/SerializationTestBitmap.cs b/test/Roaring.Net.Tests/CRoaring/TestData/SerializationTestBitmap.cs index c7b6b64..68ddbd4 100644 --- a/test/Roaring.Net.Tests/CRoaring/TestData/SerializationTestBitmap.cs +++ b/test/Roaring.Net.Tests/CRoaring/TestData/SerializationTestBitmap.cs @@ -8,29 +8,34 @@ internal static class SerializationTestBitmap public static List GetTestBitmapValues() { var values = new List(); - for (uint k = 0; k < 100000; k+= 1000) { + for (uint k = 0; k < 100000; k += 1000) + { values.Add(k); } - for (uint k = 100000; k < 200000; ++k) { - values.Add(3*k); + + for (uint k = 100000; k < 200000; ++k) + { + values.Add(3 * k); } - for (uint k = 700000; k < 800000; ++k) { + + for (uint k = 700000; k < 800000; ++k) + { values.Add(k); } return values; } - + public static Roaring32Bitmap GetTestBitmap() { - var values = GetTestBitmapValues(); + List values = GetTestBitmapValues(); var bitmap = new Roaring32Bitmap(); foreach (var value in values) - { + { bitmap.Add(value); } - + return bitmap; } } \ No newline at end of file