-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: #954 - Add TryDequeue and TryPeek Queue extension methods * feat: #954 - Use TryDequeue and TryPeek Queue extension methods * Add license * Use Queue.TryDequeue where possible * Use Queue.TryPeek where possible * Use explicit type over var * Fix tests * Run tests depending on feature flag * Reinstate previous performance optimizations * Fix QueueExtensions exception docs * Remove unnecessary ParamName assertion in QueueExtensionsTests * Add nullable support to QueueExtensions
- Loading branch information
Showing
18 changed files
with
240 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,4 +203,4 @@ public virtual IList<TernaryTreeNode> PrefixCompletion(TernaryTreeNode root, str | |
return suggest; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using System.Collections.Generic; | ||
using NUnit.Framework; | ||
|
||
using Lucene.Net.Attributes; | ||
using Lucene.Net.Util; | ||
using Lucene.Net.Support; | ||
using System; | ||
|
||
using Assert = Lucene.Net.TestFramework.Assert; | ||
|
||
|
||
namespace Lucene.Net | ||
{ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
public class QueueExtensionsTests : LuceneTestCase | ||
{ | ||
#if !FEATURE_QUEUE_TRYDEQUEUE_TRYPEEK | ||
[Test, LuceneNetSpecific] | ||
public void TryDequeue_ThrowsWhenQueueNull() | ||
{ | ||
Queue<int> queue = null; | ||
Assert.Throws<ArgumentNullException>(() => queue.TryDequeue(out int _)); | ||
} | ||
|
||
[Test, LuceneNetSpecific] | ||
public void TryDequeue_QueueEmpty() | ||
{ | ||
Queue<int> queue = new Queue<int>(); | ||
bool found = queue.TryDequeue(out int result); | ||
Assert.AreEqual(found, false); | ||
Assert.AreEqual(result, default(int)); | ||
} | ||
|
||
[Test, LuceneNetSpecific] | ||
public void TryDequeue_QueueNotEmpty() | ||
{ | ||
Queue<int> queue = new Queue<int>(); | ||
int item = 1; | ||
queue.Enqueue(item); | ||
int countBefore = queue.Count; | ||
bool found = queue.TryDequeue(out int result); | ||
Assert.AreEqual(found, true); | ||
Assert.AreEqual(result, item); | ||
Assert.AreEqual(queue.Count, countBefore - 1); | ||
} | ||
|
||
[Test, LuceneNetSpecific] | ||
public void TryPeek_ThrowsWhenQueueNull() | ||
{ | ||
Queue<int> queue = null; | ||
Assert.Throws<ArgumentNullException>(() => queue.TryPeek(out int _)); | ||
} | ||
|
||
[Test, LuceneNetSpecific] | ||
public void TryPeek_QueueEmpty() | ||
{ | ||
Queue<int> queue = new Queue<int>(); | ||
bool found = queue.TryPeek(out int result); | ||
Assert.AreEqual(found, false); | ||
Assert.AreEqual(result, default(int)); | ||
} | ||
|
||
[Test, LuceneNetSpecific] | ||
public void TryPeek_QueueNotEmpty() | ||
{ | ||
Queue<int> queue = new Queue<int>(); | ||
int item = 1; | ||
queue.Enqueue(item); | ||
int countBefore = queue.Count; | ||
bool found = queue.TryPeek(out int result); | ||
Assert.AreEqual(found, true); | ||
Assert.AreEqual(result, item); | ||
Assert.AreEqual(queue.Count, countBefore); | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.