istr-python 1.1.27__tar.gz → 1.1.28__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {istr_python-1.1.27 → istr_python-1.1.28}/PKG-INFO +15 -1
- {istr_python-1.1.27 → istr_python-1.1.28}/README.md +14 -0
- {istr_python-1.1.27 → istr_python-1.1.28}/istr/istr.py +17 -1
- {istr_python-1.1.27 → istr_python-1.1.28}/istr_python.egg-info/PKG-INFO +15 -1
- {istr_python-1.1.27 → istr_python-1.1.28}/pyproject.toml +1 -1
- {istr_python-1.1.27 → istr_python-1.1.28}/tests/test_istr.py +82 -54
- {istr_python-1.1.27 → istr_python-1.1.28}/istr/LICENSE.txt +0 -0
- {istr_python-1.1.27 → istr_python-1.1.28}/istr/__init__.py +0 -0
- {istr_python-1.1.27 → istr_python-1.1.28}/istr_python.egg-info/SOURCES.txt +0 -0
- {istr_python-1.1.27 → istr_python-1.1.28}/istr_python.egg-info/dependency_links.txt +0 -0
- {istr_python-1.1.27 → istr_python-1.1.28}/istr_python.egg-info/top_level.txt +0 -0
- {istr_python-1.1.27 → istr_python-1.1.28}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: istr-python
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.28
|
|
4
4
|
Summary: istr - strings you can count on
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/istr
|
|
@@ -395,6 +395,20 @@ istr.is_palindrome('no devil lived on') ==> True
|
|
|
395
395
|
istr.is_palindrome(min) ==> False
|
|
396
396
|
```
|
|
397
397
|
|
|
398
|
+
#### test for increasing, decreasing, non-decreasing and non-increasing
|
|
399
|
+
|
|
400
|
+
It is possible to test whether the characters of an istr are increasing, decreasing, non-decreasing or non-increasing, like
|
|
401
|
+
```
|
|
402
|
+
istr(1223).is_increasing() ==> False
|
|
403
|
+
istr(1223).is_non_decreasing() ==> True
|
|
404
|
+
istr(3221).is_decreasing() ==> False
|
|
405
|
+
istr(3221).is_non_increasing ==> True
|
|
406
|
+
```
|
|
407
|
+
It is also possible to test for 'increasingness' and friends for anything that can be converted to a str:
|
|
408
|
+
```
|
|
409
|
+
istr.is_increasing(123) ==> True
|
|
410
|
+
```
|
|
411
|
+
|
|
398
412
|
#### test for divisibility
|
|
399
413
|
|
|
400
414
|
It is possible to test whether an istr is divisible by a given value with the `is_divisible_by method,` e.g.
|
|
@@ -382,6 +382,20 @@ istr.is_palindrome('no devil lived on') ==> True
|
|
|
382
382
|
istr.is_palindrome(min) ==> False
|
|
383
383
|
```
|
|
384
384
|
|
|
385
|
+
#### test for increasing, decreasing, non-decreasing and non-increasing
|
|
386
|
+
|
|
387
|
+
It is possible to test whether the characters of an istr are increasing, decreasing, non-decreasing or non-increasing, like
|
|
388
|
+
```
|
|
389
|
+
istr(1223).is_increasing() ==> False
|
|
390
|
+
istr(1223).is_non_decreasing() ==> True
|
|
391
|
+
istr(3221).is_decreasing() ==> False
|
|
392
|
+
istr(3221).is_non_increasing ==> True
|
|
393
|
+
```
|
|
394
|
+
It is also possible to test for 'increasingness' and friends for anything that can be converted to a str:
|
|
395
|
+
```
|
|
396
|
+
istr.is_increasing(123) ==> True
|
|
397
|
+
```
|
|
398
|
+
|
|
385
399
|
#### test for divisibility
|
|
386
400
|
|
|
387
401
|
It is possible to test whether an istr is divisible by a given value with the `is_divisible_by method,` e.g.
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# |_||___/ \__||_|
|
|
6
6
|
# strings you can count on
|
|
7
7
|
|
|
8
|
-
__version__ = "1.1.
|
|
8
|
+
__version__ = "1.1.28"
|
|
9
9
|
import functools
|
|
10
10
|
import itertools
|
|
11
11
|
import types
|
|
@@ -407,6 +407,22 @@ class istr(str):
|
|
|
407
407
|
self_as_str = str(self)
|
|
408
408
|
return self_as_str == self_as_str[::-1]
|
|
409
409
|
|
|
410
|
+
def is_non_decreasing(self):
|
|
411
|
+
self_as_str = str(self)
|
|
412
|
+
return all(i0 <= i1 for i0, i1 in zip(self_as_str, self_as_str[1:]))
|
|
413
|
+
|
|
414
|
+
def is_non_increasing(self):
|
|
415
|
+
self_as_str = str(self)
|
|
416
|
+
return all(i0 >= i1 for i0, i1 in zip(self_as_str, self_as_str[1:]))
|
|
417
|
+
|
|
418
|
+
def is_increasing(self):
|
|
419
|
+
self_as_str = str(self)
|
|
420
|
+
return all(i0 < i1 for i0, i1 in zip(self_as_str, self_as_str[1:]))
|
|
421
|
+
|
|
422
|
+
def is_decreasing(self):
|
|
423
|
+
self_as_str = str(self)
|
|
424
|
+
return all(i0 > i1 for i0, i1 in zip(self_as_str, self_as_str[1:]))
|
|
425
|
+
|
|
410
426
|
def is_divisible_by(self, divisor):
|
|
411
427
|
return istr.divided_by(self, divisor) is not None
|
|
412
428
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: istr-python
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.28
|
|
4
4
|
Summary: istr - strings you can count on
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/istr
|
|
@@ -395,6 +395,20 @@ istr.is_palindrome('no devil lived on') ==> True
|
|
|
395
395
|
istr.is_palindrome(min) ==> False
|
|
396
396
|
```
|
|
397
397
|
|
|
398
|
+
#### test for increasing, decreasing, non-decreasing and non-increasing
|
|
399
|
+
|
|
400
|
+
It is possible to test whether the characters of an istr are increasing, decreasing, non-decreasing or non-increasing, like
|
|
401
|
+
```
|
|
402
|
+
istr(1223).is_increasing() ==> False
|
|
403
|
+
istr(1223).is_non_decreasing() ==> True
|
|
404
|
+
istr(3221).is_decreasing() ==> False
|
|
405
|
+
istr(3221).is_non_increasing ==> True
|
|
406
|
+
```
|
|
407
|
+
It is also possible to test for 'increasingness' and friends for anything that can be converted to a str:
|
|
408
|
+
```
|
|
409
|
+
istr.is_increasing(123) ==> True
|
|
410
|
+
```
|
|
411
|
+
|
|
398
412
|
#### test for divisibility
|
|
399
413
|
|
|
400
414
|
It is possible to test whether an istr is divisible by a given value with the `is_divisible_by method,` e.g.
|
|
@@ -256,24 +256,25 @@ def test_index():
|
|
|
256
256
|
|
|
257
257
|
def test_str_count():
|
|
258
258
|
assert istr("100").count("0") == 2
|
|
259
|
-
assert istr("100").count("0",0) ==2
|
|
260
|
-
assert istr("100").count("0",1)==2
|
|
261
|
-
assert istr("100").count("0",2)==1
|
|
262
|
-
assert istr("100").count("0",0,1)==0
|
|
263
|
-
assert istr("100").count(0)==2
|
|
264
|
-
assert istr("100").count(10)==1
|
|
265
|
-
assert istr("100").count(100)==1
|
|
266
|
-
assert istr("1000").count(100)==1
|
|
267
|
-
assert isinstance(istr("100").count(),map) # this is in fact the itertools version
|
|
259
|
+
assert istr("100").count("0", 0) == 2
|
|
260
|
+
assert istr("100").count("0", 1) == 2
|
|
261
|
+
assert istr("100").count("0", 2) == 1
|
|
262
|
+
assert istr("100").count("0", 0, 1) == 0
|
|
263
|
+
assert istr("100").count(0) == 2
|
|
264
|
+
assert istr("100").count(10) == 1
|
|
265
|
+
assert istr("100").count(100) == 1
|
|
266
|
+
assert istr("1000").count(100) == 1
|
|
267
|
+
assert isinstance(istr("100").count(), map) # this is in fact the itertools version
|
|
268
268
|
|
|
269
269
|
|
|
270
270
|
def test_itertools_count():
|
|
271
|
-
assert list(itertools.islice(istr.count(),3))==[istr(
|
|
272
|
-
assert list(istr.islice(istr.count(10),3)) ==[istr(
|
|
273
|
-
assert list(istr.islice(istr.count(istr(10)),3)) ==[istr(
|
|
274
|
-
assert list(istr.islice(istr.count(10,3),3))==[istr(
|
|
271
|
+
assert list(itertools.islice(istr.count(), 3)) == [istr("0"), istr("1"), istr("2")]
|
|
272
|
+
assert list(istr.islice(istr.count(10), 3)) == [istr("10"), istr("11"), istr("12")]
|
|
273
|
+
assert list(istr.islice(istr.count(istr(10)), 3)) == [istr("10"), istr("11"), istr("12")]
|
|
274
|
+
assert list(istr.islice(istr.count(10, 3), 3)) == [istr("10"), istr("13"), istr("16")]
|
|
275
|
+
|
|
276
|
+
assert istr.count(istr(10), 1) == 1 # this is in fact the istr version
|
|
275
277
|
|
|
276
|
-
assert istr.count(istr(10),1)==1 # this is in fact the istr version
|
|
277
278
|
|
|
278
279
|
def test_hash():
|
|
279
280
|
assert hash(istr.range(1, 13)) == hash(one_to_twelve)
|
|
@@ -347,13 +348,40 @@ def test_even_odd():
|
|
|
347
348
|
def test_is_palindrome():
|
|
348
349
|
assert istr(121).is_palindrome()
|
|
349
350
|
assert istr(1234321).is_palindrome()
|
|
350
|
-
assert not istr(123).is_palindrome()
|
|
351
|
-
assert istr(
|
|
352
|
-
assert not istr(
|
|
353
|
-
assert istr(
|
|
354
|
-
assert istr.is_palindrome(
|
|
355
|
-
assert istr.is_palindrome(121)
|
|
356
|
-
|
|
351
|
+
assert not istr(123).is_palindrome()
|
|
352
|
+
assert istr("aba").is_palindrome()
|
|
353
|
+
assert not istr("abc").is_palindrome()
|
|
354
|
+
assert istr("").is_palindrome()
|
|
355
|
+
assert istr.is_palindrome("121")
|
|
356
|
+
assert istr.is_palindrome(121)
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
def test_is_increasing_and_friends():
|
|
360
|
+
assert istr(123).is_increasing()
|
|
361
|
+
assert not istr(222).is_increasing()
|
|
362
|
+
assert not istr(321).is_increasing()
|
|
363
|
+
|
|
364
|
+
assert not istr(123).is_decreasing()
|
|
365
|
+
assert not istr(222).is_decreasing()
|
|
366
|
+
assert istr(321).is_decreasing()
|
|
367
|
+
|
|
368
|
+
assert istr(123).is_non_decreasing()
|
|
369
|
+
assert istr(222).is_non_decreasing()
|
|
370
|
+
assert not istr(321).is_non_decreasing()
|
|
371
|
+
|
|
372
|
+
assert not istr(123).is_non_increasing()
|
|
373
|
+
assert istr(222).is_non_increasing()
|
|
374
|
+
assert istr(321).is_non_increasing()
|
|
375
|
+
|
|
376
|
+
assert istr(1).is_increasing()
|
|
377
|
+
assert istr("").is_increasing()
|
|
378
|
+
|
|
379
|
+
assert not istr.is_increasing(222)
|
|
380
|
+
assert not istr.is_decreasing(222)
|
|
381
|
+
assert istr.is_non_decreasing(222)
|
|
382
|
+
assert istr.is_non_increasing(222)
|
|
383
|
+
|
|
384
|
+
|
|
357
385
|
def test_is_divisible_by():
|
|
358
386
|
assert istr(18).is_divisible_by(3)
|
|
359
387
|
assert istr(18).is_divisible_by(istr(3))
|
|
@@ -375,9 +403,9 @@ def test_divided_by():
|
|
|
375
403
|
assert istr.divided_by(18, 3).equals(istr(6))
|
|
376
404
|
assert istr.divided_by(19, 3) is None
|
|
377
405
|
assert istr.divided_by(18, 3, 0).equals(istr(6))
|
|
378
|
-
assert istr.divided_by(19, 3, 0)==0
|
|
379
|
-
assert istr.divided_by(4,0) is None
|
|
380
|
-
assert istr.divided_by(4,0,0) == 0
|
|
406
|
+
assert istr.divided_by(19, 3, 0) == 0
|
|
407
|
+
assert istr.divided_by(4, 0) is None
|
|
408
|
+
assert istr.divided_by(4, 0, 0) == 0
|
|
381
409
|
|
|
382
410
|
|
|
383
411
|
def test_is_square():
|
|
@@ -426,7 +454,7 @@ def test_is_power_of():
|
|
|
426
454
|
assert not istr(-1).is_power_of(4)
|
|
427
455
|
assert istr(-1).is_power_of(5)
|
|
428
456
|
assert istr(12345**3).is_power_of(3)
|
|
429
|
-
assert istr(-12345**3).is_power_of(3)
|
|
457
|
+
assert istr(-(12345**3)).is_power_of(3)
|
|
430
458
|
assert istr(0).is_power_of(3)
|
|
431
459
|
assert istr(1).is_power_of(3)
|
|
432
460
|
assert not istr(2).is_power_of(3)
|
|
@@ -491,10 +519,10 @@ def test_cubes():
|
|
|
491
519
|
def test_power_ofs():
|
|
492
520
|
assert istr.power_ofs(0, 1, 5) == [istr("1")]
|
|
493
521
|
assert istr.power_ofs(0, 1) == []
|
|
494
|
-
assert istr.power_ofs(1, -1, 5) == [istr("-1"),istr("0"), istr("1"), istr("2"), istr("3"), istr("4")]
|
|
522
|
+
assert istr.power_ofs(1, -1, 5) == [istr("-1"), istr("0"), istr("1"), istr("2"), istr("3"), istr("4")]
|
|
495
523
|
assert istr.power_ofs(2, -10, 10) == [istr("0"), istr("1"), istr("4"), istr("9")]
|
|
496
|
-
assert istr.power_ofs(3, -10, 10) == [istr("-8"), istr("-1"), istr("0"), istr("1"),istr("8")]
|
|
497
|
-
assert istr.power_ofs(3, -10, 9) == [istr("-8"), istr("-1"), istr("0"), istr("1"),istr("8")]
|
|
524
|
+
assert istr.power_ofs(3, -10, 10) == [istr("-8"), istr("-1"), istr("0"), istr("1"), istr("8")]
|
|
525
|
+
assert istr.power_ofs(3, -10, 9) == [istr("-8"), istr("-1"), istr("0"), istr("1"), istr("8")]
|
|
498
526
|
assert istr.power_ofs(3, -10, 8) == [istr("-8"), istr("-1"), istr("0"), istr("1")]
|
|
499
527
|
assert istr.power_ofs(4, -10, 10) == [istr("0"), istr("1")]
|
|
500
528
|
assert istr.power_ofs(2, 10, 0) == []
|
|
@@ -504,16 +532,18 @@ def test_power_ofs():
|
|
|
504
532
|
assert id(istr.power_ofs(3, 2000)) != id(istr.cubes(3, 2000)) # test caching
|
|
505
533
|
assert id(istr.power_ofs(3, 1000, cache=False)) != id(istr.cubes(3, 1000, cache=False)) # test caching
|
|
506
534
|
|
|
535
|
+
|
|
507
536
|
def test_in_range():
|
|
508
|
-
primes1000=istr.primes(1000)
|
|
509
|
-
n=len(primes1000)
|
|
510
|
-
assert len(primes1000)==n
|
|
511
|
-
assert istr.in_range(primes1000,0,5)==[istr(
|
|
512
|
-
assert istr.in_range(primes1000,0,6)==[istr(
|
|
513
|
-
assert istr.in_range(primes1000,3,6)==[istr(
|
|
514
|
-
assert len(istr.in_range(primes1000,0,998))==n
|
|
515
|
-
assert len(istr.in_range(primes1000,0,997))==n-1
|
|
516
|
-
assert len(istr.in_range(primes1000,3,997))==n-2
|
|
537
|
+
primes1000 = istr.primes(1000)
|
|
538
|
+
n = len(primes1000)
|
|
539
|
+
assert len(primes1000) == n
|
|
540
|
+
assert istr.in_range(primes1000, 0, 5) == [istr("2"), istr("3")]
|
|
541
|
+
assert istr.in_range(primes1000, 0, 6) == [istr("2"), istr("3"), istr("5")]
|
|
542
|
+
assert istr.in_range(primes1000, 3, 6) == [istr("3"), istr("5")]
|
|
543
|
+
assert len(istr.in_range(primes1000, 0, 998)) == n
|
|
544
|
+
assert len(istr.in_range(primes1000, 0, 997)) == n - 1
|
|
545
|
+
assert len(istr.in_range(primes1000, 3, 997)) == n - 2
|
|
546
|
+
|
|
517
547
|
|
|
518
548
|
def test_join():
|
|
519
549
|
s = "".join(istr(("4", "5", "6")))
|
|
@@ -683,12 +713,12 @@ def test_edge_cases():
|
|
|
683
713
|
istr()
|
|
684
714
|
rng = istr.range(5)
|
|
685
715
|
assert rng is istr(rng)
|
|
686
|
-
x = istr(5+6j)
|
|
687
|
-
assert x ==
|
|
716
|
+
x = istr(5 + 6j)
|
|
717
|
+
assert x == "(5+6j)"
|
|
688
718
|
assert not x.is_int()
|
|
689
719
|
x = istr(min)
|
|
690
|
-
assert x ==
|
|
691
|
-
assert not x.is_int()
|
|
720
|
+
assert x == "<built-in function min>"
|
|
721
|
+
assert not x.is_int()
|
|
692
722
|
|
|
693
723
|
|
|
694
724
|
def test_unpacking():
|
|
@@ -925,8 +955,7 @@ def test_sumprod():
|
|
|
925
955
|
|
|
926
956
|
|
|
927
957
|
def test_subclassing():
|
|
928
|
-
class jstr(istr.type):
|
|
929
|
-
...
|
|
958
|
+
class jstr(istr.type): ...
|
|
930
959
|
|
|
931
960
|
assert jstr(5).equals(jstr(5))
|
|
932
961
|
assert repr(jstr(*range(3))) == "(jstr('0'), jstr('1'), jstr('2'))"
|
|
@@ -972,10 +1001,10 @@ def test_compose():
|
|
|
972
1001
|
assert istr("=xyz").equals(istr(123))
|
|
973
1002
|
assert istr("=xyz", "=x") == (istr(123), istr(1))
|
|
974
1003
|
assert istr("=") == "="
|
|
975
|
-
|
|
976
|
-
assert istr(
|
|
977
|
-
assert istr(
|
|
978
|
-
|
|
1004
|
+
|
|
1005
|
+
assert istr("=09").equals(istr("09"))
|
|
1006
|
+
assert istr("=x09z").equals(istr("1093"))
|
|
1007
|
+
|
|
979
1008
|
assert istr(["=xyz", "=y"]) == [istr(123), istr(2)]
|
|
980
1009
|
|
|
981
1010
|
assert istr(dict(xyz="=xyz", y="=y")) == {"xyz": istr(123), "y": istr(2)}
|
|
@@ -986,17 +1015,16 @@ def test_compose():
|
|
|
986
1015
|
assert istr(":=xyz").equals(istr(123))
|
|
987
1016
|
assert xyz.equals(istr(123))
|
|
988
1017
|
|
|
989
|
-
assert istr(":=xyz_000").equals(istr(
|
|
990
|
-
assert xyz_000.equals(istr(
|
|
991
|
-
assert xyz_000==123000
|
|
992
|
-
|
|
1018
|
+
assert istr(":=xyz_000").equals(istr("123_000"))
|
|
1019
|
+
assert xyz_000.equals(istr("123_000"))
|
|
1020
|
+
assert xyz_000 == 123000
|
|
1021
|
+
|
|
993
1022
|
with pytest.raises(ValueError, match=re.escape(f"'0xyz' is not a valid identifier")):
|
|
994
|
-
istr(":=0xyz")
|
|
995
|
-
|
|
1023
|
+
istr(":=0xyz")
|
|
1024
|
+
|
|
996
1025
|
assert istr(":=") == ":="
|
|
997
1026
|
assert istr("=") == "="
|
|
998
1027
|
|
|
999
1028
|
|
|
1000
1029
|
if __name__ == "__main__":
|
|
1001
1030
|
pytest.main(["-vv", "-s", "-x", __file__])
|
|
1002
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|