コード例 #1
0
        public void RemoveNull_DoNothing()
        {
            using var index = new StringIndex <string>();
            var result = index.Remove(null, new string[0]);

            Assert.False(result);
        }
コード例 #2
0
        public async Task OnRemoveEmpty_RemoveEventNotInvoked(int tasksCount)
        {
            using var index = new StringIndex <string>();
            var inputs = new Dictionary <string, IEnumerable <string> >();

            for (var i = 0; i < tasksCount; i++)
            {
                inputs[Guid.NewGuid().ToString()] = new string[0];
            }

            foreach (var(q, input) in inputs)
            {
                index.Add(q, input);
            }

            var triggered = 0;

            index.Removed += (q, values) =>
            {
                var input = inputs[q];
                Assert.Equal(input, values);
                Interlocked.Increment(ref triggered);
            };

            var tasks = new List <Task>();

            foreach (var(q, input) in inputs)
            {
                tasks.Add(Task.Run(() => index.Remove(q, input)));
            }

            await Task.WhenAll(tasks);

            Assert.Equal(0, triggered);
        }
コード例 #3
0
        public async Task RemoveMultiple_GetByQuery_NotContainsRemoved(int tasksCount)
        {
            var skipTake = 3;

            using var index = new StringIndex <string>();
            var inputs = new Dictionary <string, IEnumerable <string> >();

            for (var i = 0; i < tasksCount; i++)
            {
                inputs[Guid.NewGuid().ToString()] = new []
                {
                    Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
                                               Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString()
                }
            }
            ;

            var tasks = new List <Task>();

            foreach (var(q, input) in inputs)
            {
                tasks.Add(Task.Run(() => index.Add(q, input)));
            }

            await Task.WhenAll(tasks);

            var removeTasks = new List <Task>();

            foreach (var(q, input) in inputs)
            {
                removeTasks.Add(Task.Run(() => index.Remove(q, input.Take(skipTake))));
            }

            await Task.WhenAll(removeTasks);

            var getTasks = inputs.Keys.Select(q => Task.Run(() => new { Query = q, Result = index.Get(q) })).ToList();

            await Task.WhenAll(getTasks);

            foreach (var task in getTasks)
            {
                var(query, result) = (task.Result.Query, task.Result.Result);
                var input = inputs[query].ToList();
                Assert.All(input.Skip(skipTake), x => Assert.Contains(x, result));
                Assert.All(input.Take(skipTake), x => Assert.DoesNotContain(x, result));
                Assert.Equal(input.Count - skipTake, result.Count);
            }
        }
コード例 #4
0
    public void RemoveAndSearch()
    {
        var si = new StringIndex();

        si.Add("abcdef", "1");
        si.Add("abcdeff", "2");
        si.Add("abcdeffg", "3");
        si.Add("bcdef", "4");
        si.Add("bcdefg", "5");
        si.Add("cdefg", "6");
        si.Add("cdefgh", "7");
        si.Remove("abcdef", "1");
        var output = si.GetValuesByPrefixFlattened("abc");

        Assert.IsTrue(!output.Contains("1") && output.Contains("2") && output.Contains("3"));
    }
コード例 #5
0
    public void AddAndSearchValuesCount()
    {
        var si = new StringIndex();

        si.Add("abcdef", "1");
        si.Add("abcdeff", "2");
        si.Add("abcdeffg", "3");
        si.Add("bcdef", "4");
        si.Add("bcdefg", "5");
        si.Add("cdefg", "6");
        si.Add("cdefgh", "7");
        si.Remove("cdefgh", "7");
        var output1 = si.GetValuesByPrefixCount("abc");
        var output2 = si.GetValuesByPrefixCount("b");
        var output3 = si.GetValuesByPrefixCount("bc");
        var output4 = si.GetValuesByPrefixCount("ca");

        Assert.IsTrue(output1 == 3 && output2 == 2 && output3 == 2 && output4 == 0);
    }
コード例 #6
0
        public async Task RemoveFromEmpty_GetByQuery_MustBeEmpty(int tasksCount)
        {
            using var index = new StringIndex <string>();
            var inputs = new List <string>();

            for (var i = 0; i < tasksCount; i++)
            {
                inputs.Add(Guid.NewGuid().ToString());
            }

            var removeTasks = inputs.Select(query => Task.Run(() => index.Remove(query, Guid.NewGuid().ToString()))).Cast <Task>().ToList();

            await Task.WhenAll(removeTasks);

            var getTasks = inputs.Select(q => Task.Run(() => index.Get(q))).ToList();

            await Task.WhenAll(getTasks);

            foreach (var task in getTasks)
            {
                var result = task.Result;
                Assert.Empty(result);
            }
        }