Skip to content

Commit

Permalink
test: add tests for centralization.R
Browse files Browse the repository at this point in the history
  • Loading branch information
maelle committed Dec 10, 2024
1 parent 2d60223 commit 7bf1d6a
Show file tree
Hide file tree
Showing 2 changed files with 319 additions and 0 deletions.
272 changes: 272 additions & 0 deletions tests/testthat/_snaps/centralization.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
# centr_eigen_tmax() deprecated argument

Code
centr_eigen_tmax(g, scale = FALSE)
Condition
Warning:
The `scale` argument of `centr_eigen_tmax()` is deprecated as of igraph 2.1.3.
i The function always behaves as if `scale` were TRUE. The argument will be removed in the future.
Output
[1] 998

# centr_eigen() deprecated argument

Code
centr_eigen(g, scale = FALSE)
Condition
Warning:
The `scale` argument of `centr_eigen()` is deprecated as of igraph 2.1.3.
i The function always behaves as if `scale` were TRUE. The argument will be removed in the future.
Output
$vector
[1] 1.000000000 0.951782779 0.642246897 0.936479372 0.530275870 0.221946794
[7] 0.277333202 0.152912954 0.372818029 0.127815142 0.273484729 0.115798919
[13] 0.124767961 0.347566686 0.217991682 0.155064438 0.136723710 0.142090408
[19] 0.177496493 0.112107602 0.106492916 0.065370101 0.222031054 0.117567723
[25] 0.271414853 0.099029857 0.154881109 0.114607116 0.132307797 0.164331195
[31] 0.206066997 0.115587127 0.094699049 0.073831428 0.084065500 0.102118960
[37] 0.124815177 0.125363222 0.089674288 0.074370004 0.231514975 0.099445921
[43] 0.068551677 0.131375908 0.100228495 0.082765058 0.064082598 0.102211967
[49] 0.098201796 0.059927929 0.073693479 0.032832236 0.084626988 0.096036279
[55] 0.073353690 0.084623056 0.086099928 0.060251639 0.114703698 0.091721584
[61] 0.109641146 0.058383674 0.085678160 0.095359569 0.103951017 0.092312382
[67] 0.075150933 0.070177469 0.086353818 0.104649141 0.071439692 0.088080404
[73] 0.047620875 0.093043381 0.039659823 0.075460270 0.103832299 0.093784456
[79] 0.077082705 0.060515407 0.077399837 0.115954229 0.042814406 0.091960118
[85] 0.057875582 0.087679586 0.089331459 0.051619963 0.120982244 0.047453756
[91] 0.089239711 0.070975989 0.092710224 0.052555990 0.139087062 0.101391792
[97] 0.069890894 0.076546345 0.020828121 0.095855612 0.080750621 0.098887044
[103] 0.082895480 0.090507576 0.017579818 0.065380877 0.047134558 0.050933029
[109] 0.087146700 0.074708983 0.093824859 0.062533520 0.067033062 0.030588290
[115] 0.044045285 0.066458852 0.080172941 0.059901231 0.035320924 0.103358743
[121] 0.050078816 0.019853109 0.080551867 0.112269550 0.088747061 0.047972081
[127] 0.068718578 0.098357041 0.084234299 0.033808974 0.071125928 0.027906017
[133] 0.055314049 0.049291391 0.056725343 0.057637938 0.050563887 0.086909489
[139] 0.052999728 0.081487914 0.050378585 0.063837052 0.093634682 0.047593791
[145] 0.069106157 0.093278501 0.068705520 0.066710495 0.077760976 0.051308212
[151] 0.056148788 0.054363096 0.084201404 0.075881570 0.087079863 0.035928124
[157] 0.076009680 0.050198756 0.059235718 0.035865015 0.071280492 0.101572009
[163] 0.063152025 0.069038954 0.061658994 0.034813668 0.037303850 0.073796627
[169] 0.063073429 0.059234345 0.078849469 0.052419850 0.060876075 0.083284938
[175] 0.062517079 0.089605425 0.096373429 0.069577444 0.063479199 0.095043924
[181] 0.093030939 0.048537495 0.028721340 0.061061072 0.072608682 0.069030823
[187] 0.046854812 0.091306544 0.038613428 0.066972740 0.063957853 0.050227363
[193] 0.091017737 0.042787565 0.086089915 0.019594407 0.095245783 0.087367843
[199] 0.054278197 0.052589566 0.049235085 0.063967499 0.055943715 0.033881900
[205] 0.048661624 0.053062628 0.043921042 0.047449220 0.105732305 0.033227399
[211] 0.091934435 0.081583766 0.053292210 0.030681303 0.046294426 0.076642411
[217] 0.126774863 0.079188246 0.085652734 0.042506195 0.049004081 0.085908843
[223] 0.080170794 0.109184449 0.052514808 0.020538965 0.057454547 0.049727626
[229] 0.101115821 0.061942388 0.067005672 0.120415287 0.071083465 0.055856229
[235] 0.091912004 0.086742127 0.017395434 0.050816919 0.062233448 0.095086382
[241] 0.043153173 0.071777453 0.024834094 0.047936076 0.046983369 0.055568450
[247] 0.026307947 0.051117286 0.048642607 0.044682735 0.047472869 0.082982776
[253] 0.061155735 0.034776887 0.076666198 0.040139125 0.039962716 0.091313107
[259] 0.041985681 0.094214109 0.099747859 0.082400888 0.077434043 0.054325775
[265] 0.089510524 0.022394525 0.051588639 0.058536877 0.103649197 0.058435605
[271] 0.042612318 0.082381743 0.039386878 0.049403742 0.077121441 0.088725561
[277] 0.069228273 0.054532909 0.037727266 0.030103851 0.040293374 0.048696997
[283] 0.026393702 0.035245353 0.048025177 0.030138415 0.048938857 0.038891599
[289] 0.061070044 0.049161103 0.021557565 0.075057751 0.046807313 0.024796747
[295] 0.027315335 0.044147605 0.052702756 0.032450661 0.056333911 0.013873630
[301] 0.068325664 0.061590728 0.034076902 0.077076485 0.067521406 0.080263670
[307] 0.060187542 0.032714801 0.051888333 0.063263179 0.045133898 0.018722066
[313] 0.049195975 0.023310111 0.049919256 0.076401651 0.037111878 0.063332384
[319] 0.075522741 0.024056845 0.118552679 0.079974830 0.052330249 0.047516036
[325] 0.064513465 0.099523827 0.109342933 0.078320022 0.046889511 0.053216983
[331] 0.024329467 0.049215812 0.029733180 0.029330118 0.018902502 0.083121108
[337] 0.028617874 0.048478573 0.049856754 0.025341676 0.079215851 0.096356371
[343] 0.042886894 0.020754082 0.083856675 0.040398505 0.061929347 0.062986818
[349] 0.079596277 0.052015592 0.048419153 0.053767324 0.048089513 0.066476889
[355] 0.021313645 0.064445991 0.092122785 0.070630468 0.095081803 0.067054799
[361] 0.054045996 0.018559258 0.055731446 0.028328542 0.049339257 0.043008173
[367] 0.044664630 0.017325373 0.047587075 0.045830322 0.058175537 0.073718777
[373] 0.053041673 0.110787973 0.055111294 0.047604205 0.081859755 0.026112344
[379] 0.052670977 0.054335195 0.072380479 0.080148287 0.070909353 0.017678807
[385] 0.059001568 0.057891791 0.035719076 0.072544978 0.047587963 0.051109855
[391] 0.066736067 0.048787716 0.052582619 0.090388416 0.050769456 0.026834621
[397] 0.025468951 0.082747333 0.044220153 0.037024547 0.017784737 0.047655722
[403] 0.063044358 0.022594362 0.083148961 0.079289762 0.079415432 0.096116334
[409] 0.060976317 0.037806209 0.093113901 0.052791932 0.057700554 0.019269742
[415] 0.090400687 0.045643006 0.105241933 0.078200492 0.082694827 0.041196470
[421] 0.049394119 0.046861355 0.023392626 0.053295173 0.049123182 0.086544419
[427] 0.040931725 0.076650165 0.075540758 0.076786786 0.026115740 0.072837065
[433] 0.064218492 0.046991830 0.091169726 0.023184011 0.062627162 0.063867786
[439] 0.065309360 0.018803007 0.041424367 0.047021876 0.022500513 0.041987114
[445] 0.048787114 0.051389002 0.026100584 0.047520262 0.081810001 0.063253749
[451] 0.046954591 0.031307687 0.077841963 0.073564094 0.015952570 0.026961228
[457] 0.036834834 0.017084573 0.013487777 0.031112050 0.059517615 0.073080784
[463] 0.051561148 0.042589086 0.041165279 0.043007998 0.075048999 0.037617978
[469] 0.044400255 0.051145922 0.055577782 0.072736508 0.071727148 0.047367806
[475] 0.054537919 0.034341306 0.044311573 0.075978093 0.029917693 0.042053169
[481] 0.038689006 0.090044644 0.080265640 0.074988027 0.045129205 0.061911694
[487] 0.018376852 0.110778727 0.091485158 0.036763538 0.051359212 0.035692339
[493] 0.021771912 0.013225568 0.073436731 0.032070306 0.058709006 0.038639690
[499] 0.019925255 0.039477966 0.053038889 0.043777240 0.012219620 0.013235060
[505] 0.044884595 0.050003853 0.026035707 0.047560258 0.044812455 0.052904556
[511] 0.072231303 0.019007156 0.096460950 0.012598988 0.037720990 0.052125041
[517] 0.010773345 0.014903137 0.054641865 0.050813610 0.030368356 0.013267326
[523] 0.047909148 0.040224589 0.047045527 0.013005534 0.050633205 0.044465155
[529] 0.043933639 0.060464619 0.074680185 0.045798179 0.043956674 0.078261931
[535] 0.081005713 0.031223931 0.020389615 0.089989055 0.090288914 0.040492571
[541] 0.051515870 0.074501785 0.022610339 0.023445547 0.107234313 0.022522208
[547] 0.021562357 0.089970365 0.034311262 0.038422966 0.059446865 0.060374035
[553] 0.047440707 0.074015075 0.020079995 0.042293428 0.045519649 0.072370875
[559] 0.073256788 0.051189455 0.020755952 0.047131571 0.043346597 0.027024071
[565] 0.077187242 0.024631905 0.043125428 0.019084553 0.044476728 0.050597563
[571] 0.065923601 0.056938100 0.042564285 0.033882689 0.053038361 0.010955366
[577] 0.061264099 0.033735094 0.091645017 0.040652225 0.089500675 0.054696508
[583] 0.019714867 0.065291477 0.058816440 0.053327429 0.043713713 0.012635358
[589] 0.053657042 0.030663304 0.023622034 0.046447043 0.022108674 0.070610970
[595] 0.054860086 0.079285163 0.078653604 0.020212817 0.057635013 0.044951135
[601] 0.059646732 0.047985847 0.026030338 0.018087053 0.013402565 0.075614181
[607] 0.061285348 0.026466687 0.052029358 0.047533811 0.046308420 0.054796824
[613] 0.063809543 0.061925649 0.045782584 0.037798229 0.043287442 0.022533324
[619] 0.065096240 0.068259501 0.055745265 0.042891426 0.041891905 0.032421407
[625] 0.008846182 0.024409397 0.031563947 0.070727362 0.055139536 0.046958476
[631] 0.080425885 0.026644049 0.048151230 0.057262127 0.066294507 0.057096268
[637] 0.057976048 0.013376928 0.049831692 0.039613384 0.044623672 0.042096383
[643] 0.017990913 0.033069732 0.055699106 0.055392798 0.043734210 0.041560976
[649] 0.063064213 0.043324527 0.035890551 0.063728286 0.075931064 0.004870161
[655] 0.050919557 0.093845271 0.069140567 0.095497358 0.039027601 0.040179802
[661] 0.032798978 0.057105826 0.061753045 0.027819430 0.030870507 0.016484237
[667] 0.034647245 0.065801857 0.016092981 0.071373841 0.069799061 0.014581118
[673] 0.039902849 0.028595977 0.008420429 0.023078956 0.059063931 0.080908693
[679] 0.039405608 0.039570830 0.049271968 0.044615748 0.077428930 0.007926569
[685] 0.096743356 0.073631212 0.071292314 0.009759679 0.071471008 0.060311211
[691] 0.031623231 0.044788222 0.048331951 0.025422020 0.042953775 0.054956479
[697] 0.052049372 0.065449770 0.013419557 0.034542883 0.019288685 0.052108497
[703] 0.008500101 0.047188579 0.056561998 0.065881412 0.046110047 0.055611454
[709] 0.048824144 0.051039393 0.103296718 0.063002753 0.068821551 0.045210603
[715] 0.049366365 0.019957588 0.016765433 0.075729983 0.020634534 0.022443541
[721] 0.039684913 0.023469674 0.025446708 0.047135925 0.057454755 0.074018112
[727] 0.049560643 0.030564493 0.067441334 0.057943604 0.083138841 0.048972093
[733] 0.017956758 0.040078121 0.062072487 0.076211744 0.040620466 0.014073322
[739] 0.034371910 0.042426947 0.048503957 0.078619510 0.022142954 0.019365134
[745] 0.029411087 0.046373564 0.020102371 0.051232147 0.054582511 0.020600807
[751] 0.080130178 0.018554617 0.046799410 0.061665370 0.049909819 0.028887544
[757] 0.041928641 0.072107545 0.048044631 0.017500148 0.079704981 0.019800428
[763] 0.078847606 0.027728581 0.062140507 0.052875436 0.050314453 0.031264096
[769] 0.040692410 0.063381844 0.093112844 0.065514455 0.030215636 0.008162284
[775] 0.083515809 0.030508862 0.071381480 0.033193456 0.038807775 0.048577287
[781] 0.094040882 0.042417501 0.034179279 0.060709420 0.023967613 0.045554017
[787] 0.074456233 0.075916650 0.059880119 0.011481273 0.047862588 0.061598045
[793] 0.077855098 0.069704264 0.043405298 0.050504729 0.071719399 0.040369625
[799] 0.045942537 0.092614205 0.012672154 0.045608046 0.040667386 0.040865332
[805] 0.059014656 0.045852608 0.078073363 0.062309122 0.043576468 0.029046765
[811] 0.042816950 0.009977487 0.077522706 0.045081357 0.040872934 0.047231595
[817] 0.015038766 0.083482749 0.068779445 0.093969989 0.026748163 0.057670367
[823] 0.047955946 0.036966760 0.036353827 0.017255520 0.042898388 0.043051994
[829] 0.074833042 0.086307313 0.045436924 0.059221541 0.047478158 0.044306617
[835] 0.046169643 0.045687496 0.060795761 0.034734123 0.063653303 0.011347272
[841] 0.085289303 0.022174998 0.027379326 0.050475597 0.042596285 0.051923358
[847] 0.048399611 0.046948200 0.062840319 0.074631473 0.110580846 0.039832647
[853] 0.038174593 0.015025078 0.080533856 0.041301980 0.063296963 0.020530113
[859] 0.069595043 0.014460265 0.041985769 0.074297970 0.024510919 0.052501898
[865] 0.075321819 0.048182633 0.005945560 0.045073331 0.047886060 0.059263097
[871] 0.039615085 0.023340750 0.074906885 0.049034429 0.042430824 0.068803826
[877] 0.036763154 0.063089290 0.047234126 0.048488930 0.048866123 0.060128977
[883] 0.016108230 0.050418349 0.021166057 0.013600525 0.039284472 0.080969373
[889] 0.109342933 0.010672715 0.015890713 0.079891885 0.044434137 0.067109433
[895] 0.050792579 0.073307023 0.059478730 0.039223108 0.020887049 0.011867962
[901] 0.054100765 0.051787720 0.038661031 0.057934446 0.044151425 0.050531877
[907] 0.041721609 0.032173332 0.079836726 0.043600493 0.062540728 0.034957414
[913] 0.033379850 0.018010754 0.040073088 0.033828301 0.043203573 0.020463858
[919] 0.074909540 0.050186062 0.103871477 0.023921037 0.035718606 0.011934061
[925] 0.013064042 0.045987177 0.013903593 0.052133312 0.039279884 0.086646795
[931] 0.068955557 0.042221241 0.022493439 0.021500039 0.044985654 0.051574362
[937] 0.030682564 0.109342933 0.011537177 0.035661913 0.008851006 0.054222338
[943] 0.036444284 0.008028752 0.045453142 0.031193299 0.006664672 0.044180981
[949] 0.059987344 0.058866418 0.013810648 0.059813757 0.038475702 0.080534501
[955] 0.075821819 0.010591476 0.029079798 0.030443812 0.030777806 0.041366492
[961] 0.011267016 0.102139472 0.029180735 0.027080918 0.057907415 0.038709278
[967] 0.061314807 0.049525614 0.035266067 0.050082791 0.063986063 0.090771694
[973] 0.098552181 0.011492223 0.020429320 0.040802768 0.051227731 0.021504083
[979] 0.013573813 0.058403225 0.010837678 0.040702917 0.071009852 0.042605726
[985] 0.008026109 0.050258651 0.050100616 0.014397933 0.037112250 0.047654021
[991] 0.044427764 0.079536876 0.007986134 0.013574124 0.006942530 0.102244877
[997] 0.043994191 0.015266164 0.017255528 0.041242677
$value
[1] 28.57346
$options
$options$bmat
[1] "I"
$options$n
[1] 1000
$options$which
[1] "LA"
$options$nev
[1] 1
$options$tol
[1] 0
$options$ncv
[1] 0
$options$ldv
[1] 0
$options$ishift
[1] 1
$options$maxiter
[1] 3000
$options$nb
[1] 1
$options$mode
[1] 1
$options$start
[1] 1
$options$sigma
[1] 0
$options$sigmai
[1] 0
$options$info
[1] 0
$options$iter
[1] 2
$options$nconv
[1] 1
$options$numop
[1] 30
$options$numopb
[1] 0
$options$numreo
[1] 17
$centralization
[1] 0.9408464
$theoretical_max
[1] 998

# centr_degree_tmax() deprecated argument

Code
centr_degree_tmax(g)
Condition
Warning:
The `loops` argument of `centr_degree_tmax()` must be explicit as of igraph 2.0.0.
i Default value (`FALSE`) will be dropped in next release, add an explicit value for the loops argument.
Output
[1] 1994004

47 changes: 47 additions & 0 deletions tests/testthat/test-centralization.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
test_that("centr_eigen_tmax() works", {
withr::local_seed(42)
g <- sample_pa(1000, m = 4)
expect_equal(centr_eigen_tmax(g), 998)
})

test_that("centr_eigen_tmax() deprecated argument", {
g <- sample_pa(1000, m = 4)
expect_snapshot(centr_eigen_tmax(g, scale = FALSE))
})

test_that("centr_eigen() works", {
withr::local_seed(42)
g <- sample_pa(1000, m = 4)
centr_eigen <- centr_eigen(g)
expect_setequal(
names(centr_eigen),
c("vector", "value", "options", "centralization", "theoretical_max")
)
expect_equal(centr_eigen$centralization, 0.9432924, tolerance = 1e-06)
})

test_that("centr_eigen() deprecated argument", {
g <- sample_pa(1000, m = 4)
expect_snapshot(centr_eigen(g, scale = FALSE))
})

test_that("centr_degree_tmax() works", {
withr::local_seed(42)
g <- sample_pa(1000, m = 4)
expect_gt(centr_degree_tmax(g, loops = TRUE), 1990000)
})

test_that("centr_degree_tmax() deprecated argument", {
g <- sample_pa(1000, m = 4)
expect_snapshot(centr_degree_tmax(g))
})

test_that("centr_betw() works", {
withr::local_seed(42)
g <- sample_pa(1000, m = 4)
expect_setequal(
names(centr_betw(g)),
c("res", "centralization", "theoretical_max")
)
expect_equal(centr_betw(g)$theoretical_max, 996004998)
})

0 comments on commit 7bf1d6a

Please sign in to comment.