blob: 73921ea8778fdc2475f9c1ec66a1fc26f47f0622 [file] [log] [blame]
Jens Geyer3cac3202022-01-31 18:04:35 +01001// Licensed to the Apache Software Foundation(ASF) under one
Jens Geyeraa0c8b32019-01-28 23:27:45 +01002// or more contributor license agreements.See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18using System;
19using System.Collections.Generic;
20using System.Linq;
21using System.Text;
22using Microsoft.VisualStudio.TestTools.UnitTesting;
23using Thrift.Collections;
24
Jens Geyer3cac3202022-01-31 18:04:35 +010025#pragma warning disable IDE0063 // simplify using
26
Jens Geyeraa0c8b32019-01-28 23:27:45 +010027namespace Thrift.Tests.Collections
28{
29 // ReSharper disable once InconsistentNaming
30 [TestClass]
31 public class THashSetTests
32 {
33 [TestMethod]
34 public void THashSet_Equals_Primitive_Test()
35 {
36 const int value = 1;
37
Jens Geyer3cac3202022-01-31 18:04:35 +010038 var hashSet = new HashSet<int> {value};
Jens Geyeraa0c8b32019-01-28 23:27:45 +010039
40 Assert.IsTrue(hashSet.Contains(value));
41
42 hashSet.Remove(value);
43
44 Assert.IsTrue(hashSet.Count == 0);
45
46 hashSet.Add(value);
47
48 Assert.IsTrue(hashSet.Contains(value));
49
50 hashSet.Clear();
51
52 Assert.IsTrue(hashSet.Count == 0);
53
54 var newArr = new int[1];
55 hashSet.Add(value);
56 hashSet.CopyTo(newArr, 0);
57
58 Assert.IsTrue(newArr.Contains(value));
59
60 var en = hashSet.GetEnumerator();
61 en.MoveNext();
62
63 Assert.IsTrue((int)en.Current == value);
64
65 using (var ien = ((IEnumerable<int>)hashSet).GetEnumerator())
66 {
67 ien.MoveNext();
68
69 Assert.IsTrue(ien.Current == value);
70 }
71 }
72 }
73}