-
Notifications
You must be signed in to change notification settings - Fork 774
Expand file tree
/
Copy pathtest_mp_length.py
More file actions
49 lines (40 loc) · 1.54 KB
/
test_mp_length.py
File metadata and controls
49 lines (40 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*-
"""Test __len__ for .NET classes implementing ICollection/ICollection<T>."""
import System
import pytest
from Python.Test import MpLengthCollectionTest, MpLengthExplicitCollectionTest, MpLengthGenericCollectionTest, MpLengthExplicitGenericCollectionTest
def test_simple___len__():
"""Test __len__ for simple ICollection implementers"""
import System
import System.Collections.Generic
l = System.Collections.Generic.List[int]()
assert len(l) == 0
l.Add(5)
l.Add(6)
assert len(l) == 2
d = System.Collections.Generic.Dictionary[int, int]()
assert len(d) == 0
d.Add(4, 5)
assert len(d) == 1
a = System.Array[int]([0,1,2,3])
assert len(a) == 4
def test_custom_collection___len__():
"""Test __len__ for custom collection class"""
s = MpLengthCollectionTest()
assert len(s) == 3
def test_custom_collection_explicit___len__():
"""Test __len__ for custom collection class that explicitly implements ICollection"""
s = MpLengthExplicitCollectionTest()
assert len(s) == 2
def test_custom_generic_collection___len__():
"""Test __len__ for custom generic collection class"""
s = MpLengthGenericCollectionTest[int]()
s.Add(1)
s.Add(2)
assert len(s) == 2
def test_custom_generic_collection_explicit___len__():
"""Test __len__ for custom generic collection that explicity implements ICollection<T>"""
s = MpLengthExplicitGenericCollectionTest[int]()
s.Add(1)
s.Add(10)
assert len(s) == 2