Skip to content

Commit 7738e82

Browse files
authored
Merge pull request #105 from bockthom/thomas-updates
Some fixes to README, range construction, vertex attributes, and network-splitting functions Reviewed-by: Claus Hunsen <[email protected]>
2 parents 70a66fb + d1e15ff commit 7738e82

File tree

8 files changed

+365
-76
lines changed

8 files changed

+365
-76
lines changed

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ Install the library using the guide in our [README](README.md) file. Start imple
105105
In our development process, we pursue the following idea:
106106
- Each version (i.e., a tag) contains, at least, a major and a minor version in the form `v{major}.{minor}[.{bugfix}]`.
107107
- The branch `master` should always contain the most recent and complete version.
108-
- For each version, we maintain a stable branch `v{major}.{minor}-fixes` (e.g., `v3.0-fixes`) containing backported fixes for this particular version. Sometimes, we will annotate such branches with continuous version numbers indicating bugfix releases (e.g., `v3.0.2`).
108+
- Usually, we release a new version (i.e., a tag) after bugfixes to the most recent version (e.g., when fixing some bugs after release `v3.1`, we introduce a new version `v3.1.1` containing the bugfixes.
109+
- When fixing some extreme bugs, we maintain a stable branch `v{major}.{minor}-fixes` (e.g., `v2.0-fixes`) for the second last major version containing backported fixes for this particular version (e.g., when we fix a extreme bug in version `v3.1` by introducing version `v3.1.1`, we might backport the fix to major version 2 by maintaining a branch `v2.x-fixes` where `x` denotes the last minor version belonging to major version 2.)
109110
- The current development will be performed on the branch `dev`, i.e., all incoming pull requests are against this branch.
110111

111112
The current build status is as follows:

NEWS.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# codeface-extraction-r - Changelog
22

3+
## unversioned
4+
5+
### Added
6+
7+
8+
### Changed/Improved
9+
- Improve performance of several functions used for adding vertex attributes (#102, PR #105)
10+
- Change default values for aggregation levels for some functions (#102, PR #105)
11+
- Add missing `remove.isolates` parameter to some more network-splitting functions (011328e881b09bd736dc83475ba7e6cab663bebe)
12+
- Some minor improvements to the test suite
13+
14+
### Fixed
15+
- Fix outdated statements in README.md (PR #105)
16+
- Fix range construction when difference between `start` and `end` is smaller than `time.period` (#103, PR #105, 975ae4d2e1b954d92f945c5853959ff2b3e47083)
17+
318

419
## 3.1
520

@@ -33,7 +48,7 @@
3348

3449
## 3.0.1
3550

36-
## Added
51+
### Added
3752
- Add committer data to commit data source (#35, 251cfdbac0ab31584a7fab8bbaf8398a53ae8d11)
3853
- Add function to delete isolate vertices from a network (5d91ddd89a488212eabf2ce110ec7210fc3c971d)
3954

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ It may lead to unpredictable behavior, when you do not do this, as we need to se
2626
When selecting a version to work with, you should consider the following points:
2727
- Each version (i.e., a tag) contains, at least, a major and a minor version in the form `v{major}.{minor}[.{bugfix}]`.
2828
- On the branch `master`, there is always the most recent and complete version.
29-
- You should always work with the current version on the `master` branch, *unless* there is a branch called `{your_version}-fixes` (e.g., `v3.0-fixes`), then select this one as it contains backported bugfixes for this version. Sometimes, we will annotate such branches with continuous version numbers indicating bugfix releases (e.g., `v3.0.2`).
29+
- You should always work with the current version on the `master` branch. If you, nentheless, work on a former version, there might be a branch called `{your_version}-fixes` (e.g., `v2.3-fixes`) when we have fixed some extreme bugs in the current version, then select this one as it contains backported bugfixes for the former version. We will backport some very important bugfixes only in special cases and only for the last minor version of the second last major version.
3030
- If you are confident enough, you can use the `dev` branch.
3131

3232
### Needed R packages
@@ -261,8 +261,8 @@ Updates to the parameters can be done by calling `NetworkConf$update.variables(.
261261
* **Note**: This parameter does not affect the original data object, but rather creates a clone.
262262
* [`TRUE`, *`FALSE`*]
263263

264-
The classes `ProjectData` and `RangeData` hold instances of the `NetworkConf` class, just pass the object as parameter to the constructor.
265-
You can also update the object at any time, but as soon as you do so, all cached data of the data object are reset and have to be rebuilt.
264+
The class `NetworkBuilder` holds an instance of the `NetworkConf` class, just pass the object as parameter to the constructor.
265+
You can also update the `NetworkConf` object at any time by calling `NetworkBuilder$update.network.conf(...)`, but as soon as you do so, all cached data of the `NetworkBuilder` object are reset and have to be rebuilt.
266266

267267
For more examples, please look in the file `showcase.R`.
268268

tests/test-misc.R

Lines changed: 138 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,100 @@
1313
##
1414
## Copyright 2017 by Felix Prasse <[email protected]>
1515
## Copyright 2017-2018 by Claus Hunsen <[email protected]>
16-
## Copyright 2017 by Thomas Bock <[email protected]>
16+
## Copyright 2017-2018 by Thomas Bock <[email protected]>
1717
## All Rights Reserved.
1818

1919

20+
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
21+
## Parameter verification --------------------------------------------------
22+
23+
##
24+
## Match argument or take default.
25+
##
26+
27+
test_that("Match argument or take default.", {
28+
29+
## 1) tests for single choice without default
30+
test.function = function(param = c("choice1", "choice2", "choice3")) {
31+
param = match.arg.or.default(param)
32+
return(param)
33+
}
34+
35+
actual.result = test.function()
36+
expected.result = "choice1"
37+
expect_equal(actual.result, expected.result, info = "Single choice without default, no choice")
38+
39+
actual.result = test.function("choice3")
40+
expected.result = "choice3"
41+
expect_equal(actual.result, expected.result, info = "Single choice without default, one choice")
42+
43+
expect_error(test.function(c("choice3", "choice1")), info = "Single choice with default, two choices")
44+
45+
## 2) tests for single choice with default
46+
test.function = function(param = c("choice1", "choice2", "choice3")) {
47+
param = match.arg.or.default(param, default = "choice2")
48+
return(param)
49+
}
50+
51+
actual.result = test.function()
52+
expected.result = "choice2"
53+
expect_equal(actual.result, expected.result, info = "Single choice with default, no choice")
54+
55+
actual.result = test.function("choice3")
56+
expected.result = "choice3"
57+
expect_equal(actual.result, expected.result, info = "Single choice with default, one choice")
58+
59+
actual.result = test.function(c("choice3", "choice1"))
60+
expected.result = "choice2"
61+
expect_equal(actual.result, expected.result, info = "Single choice without default, two choices")
62+
63+
## 3) tests for single choice with illegal default
64+
test.function = function(param = c("choice1", "choice2", "choice3")) {
65+
param = match.arg.or.default(param, default = "c2")
66+
return(param)
67+
}
68+
69+
expect_error(test.function(), info = "Single choice with illegal default, no choice")
70+
expect_error(test.function(c("choice3", "choice1")), info = "Single choice with illegal default, one choice")
71+
expect_error(test.function(c("choice3", "choice1")), info = "Single choice with illegal default, two choices")
72+
73+
## 4) tests for multiple choices
74+
test.function = function(param = c("choice1", "choice2", "choice3")) {
75+
param = match.arg.or.default(param, several.ok = TRUE)
76+
return(param)
77+
}
78+
79+
actual.result = test.function()
80+
expected.result = c("choice1", "choice2", "choice3")
81+
expect_equal(actual.result, expected.result, info = "Multiple choices, no choice")
82+
83+
actual.result = test.function("choice3")
84+
expected.result = "choice3"
85+
expect_equal(actual.result, expected.result, info = "Multiple choices, one choice")
86+
87+
actual.result = test.function(c("choice3", "choice1"))
88+
expected.result = c("choice3", "choice1")
89+
expect_equal(actual.result, expected.result, info = "Multiple choices, two choices")
90+
91+
## 5) tests for multiple choices with ignored default
92+
test.function = function(param = c("choice1", "choice2", "choice3")) {
93+
param = match.arg.or.default(param, default = "choice2", several.ok = TRUE)
94+
return(param)
95+
}
96+
97+
actual.result = test.function()
98+
expected.result = c("choice1", "choice2", "choice3")
99+
expect_equal(actual.result, expected.result, info = "Multiple choices with ignored default, no choice")
100+
101+
actual.result = test.function("choice3")
102+
expected.result = "choice3"
103+
expect_equal(actual.result, expected.result, info = "Multiple choices with ignored default, one choice")
104+
105+
actual.result = test.function(c("choice3", "choice1"))
106+
expected.result = c("choice3", "choice1")
107+
expect_equal(actual.result, expected.result, info = "Multiple choices with ignored default, two choices")
108+
})
109+
20110
## / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
21111
## Date handling -----------------------------------------------------------
22112

@@ -238,6 +328,53 @@ test_that("Construct cumulative ranges.", {
238328
## TODO use expect_identical here? why failing?
239329
})
240330

331+
##
332+
## Construct ranges when difference between start and end is smaller than time period.
333+
##
334+
335+
test_that("Construct ranges when difference between start and end is smaller than time period.", {
336+
337+
start = ("2015-05-01 01:01:01")
338+
start.date = get.date.from.string(start)
339+
end = ("2015-05-02 02:02:02")
340+
end.date = get.date.from.string(end)
341+
end.including = end.date + 1
342+
343+
## expected results (equal for consecutive, cumulative, and overlapping range construction)
344+
expected.formatted = c("2015-05-01 01:01:01-2015-05-02 02:02:03")
345+
expected.raw = lapply(expected.formatted, get.range.bounds)
346+
names(expected.raw) = expected.formatted
347+
348+
## consecutive
349+
## 1) formatted
350+
result.formatted = construct.consecutive.ranges(start, end, time.period = "1 week", raw = FALSE)
351+
expect_identical(result.formatted, expected.formatted, info = "Consecutive range (formatted).")
352+
## 2) raw
353+
result.raw = construct.consecutive.ranges(start, end, time.period = "1 week", raw = TRUE)
354+
expect_equal(result.raw, expected.raw, info = "Consecutive range (raw).")
355+
## TODO use expect_identical here? why failing?
356+
357+
## cumulative
358+
## 1) formatted
359+
result.formatted = construct.cumulative.ranges(start, end, time.period = "1 week", raw = FALSE)
360+
expect_identical(result.formatted, expected.formatted, info = "Cumulative range (formatted).")
361+
## 2) raw
362+
result.raw = construct.cumulative.ranges(start, end, time.period = "1 week", raw = TRUE)
363+
expect_equal(result.raw, expected.raw, info = "Cumulative range (raw).")
364+
## TODO use expect_identical here? why failing?
365+
366+
## overlapping
367+
## 1) formatted
368+
result.formatted = construct.overlapping.ranges(start, end, time.period = "1 week",
369+
overlap = "1 day", raw = FALSE)
370+
expect_identical(result.formatted, expected.formatted, info = "Overlapping range (formatted).")
371+
## 2) raw
372+
result.raw = construct.overlapping.ranges(start, end, time.period = "1 week",
373+
overlap = "5 days", raw = TRUE)
374+
expect_equal(result.raw, expected.raw, info = "Overlapping range (raw).")
375+
## TODO use expect_identical here? why failing?
376+
})
377+
241378
##
242379
## Aggregate ranges.
243380
##

tests/test-network-covariates.R

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -491,16 +491,33 @@ test_that("Test add.vertex.attribute.artifact.editor.count", {
491491

492492
networks.and.data = get.network.covariates.test.networks("artifact")
493493

494-
expected.attributes = network.covariates.test.build.expected(list(1L), list(1L), list(3L, 1L))
494+
expected.attributes = list(
495+
range = network.covariates.test.build.expected(
496+
list(1L), list(1L), list(3L, 1L)),
497+
cumulative = network.covariates.test.build.expected(
498+
list(1L), list(2L), list(3L, 1L)),
499+
all.ranges = network.covariates.test.build.expected(
500+
list(2L), list(2L), list(3L, 1L)),
501+
project.cumulative = network.covariates.test.build.expected(
502+
list(1L), list(2L), list(3L, 1L)),
503+
project.all.ranges = network.covariates.test.build.expected(
504+
list(2L), list(2L), list(3L, 1L)),
505+
complete = network.covariates.test.build.expected(
506+
list(2L), list(2L), list(3L, 1L))
507+
)
495508

496509
## Test
497510

498-
networks.with.attr = add.vertex.attribute.artifact.editor.count(networks.and.data[["networks"]],
499-
networks.and.data[["project.data"]])
511+
lapply(AGGREGATION.LEVELS, function(level) {
512+
networks.with.attr = add.vertex.attribute.artifact.editor.count(
513+
networks.and.data[["networks"]], networks.and.data[["project.data"]],
514+
aggregation.level = level
515+
)
500516

501-
actual.attributes = lapply(networks.with.attr, igraph::get.vertex.attribute, name = "editor.count")
517+
actual.attributes = lapply(networks.with.attr, igraph::get.vertex.attribute, name = "editor.count")
502518

503-
expect_identical(expected.attributes, actual.attributes)
519+
expect_equal(expected.attributes[[level]], actual.attributes)
520+
})
504521
})
505522

506523
#' Test the add.vertex.attribute.artifact.first.occurrence method
@@ -510,20 +527,45 @@ test_that("Test add.vertex.attribute.artifact.first.occurrence", {
510527

511528
networks.and.data = get.network.covariates.test.networks("artifact")
512529

513-
expected.attributes = network.covariates.test.build.expected(
514-
dateList("2016-07-12 15:58:59 UTC"), dateList("2016-07-12 16:00:45 UTC"),
515-
dateList("2016-07-12 16:05:41 UTC", "2016-07-12 16:06:32 UTC")
530+
expected.attributes = list(
531+
range = network.covariates.test.build.expected(
532+
dateList("2016-07-12 15:58:59 UTC"), dateList("2016-07-12 16:00:45 UTC"),
533+
dateList("2016-07-12 16:05:41 UTC", "2016-07-12 16:06:32 UTC")
534+
),
535+
cumulative = network.covariates.test.build.expected(
536+
dateList("2016-07-12 15:58:59 UTC"), dateList("2016-07-12 15:58:59 UTC"),
537+
dateList("2016-07-12 16:05:41 UTC", "2016-07-12 16:06:32 UTC")
538+
),
539+
all.ranges = network.covariates.test.build.expected(
540+
dateList("2016-07-12 15:58:59 UTC"), dateList("2016-07-12 15:58:59 UTC"),
541+
dateList("2016-07-12 16:05:41 UTC", "2016-07-12 16:06:32 UTC")
542+
),
543+
project.cumulative = network.covariates.test.build.expected(
544+
dateList("2016-07-12 15:58:59 UTC"), dateList("2016-07-12 15:58:59 UTC"),
545+
dateList("2016-07-12 16:05:41 UTC", "2016-07-12 16:06:32 UTC")
546+
),
547+
project.all.ranges = network.covariates.test.build.expected(
548+
dateList("2016-07-12 15:58:59 UTC"), dateList("2016-07-12 15:58:59 UTC"),
549+
dateList("2016-07-12 16:05:41 UTC", "2016-07-12 16:06:32 UTC")
550+
),
551+
complete = network.covariates.test.build.expected(
552+
dateList("2016-07-12 15:58:59 UTC"), dateList("2016-07-12 15:58:59 UTC"),
553+
dateList("2016-07-12 16:05:41 UTC", "2016-07-12 16:06:32 UTC")
554+
)
516555
)
517556

518557
## Test
519558

520-
networks.with.attr = add.vertex.attribute.artifact.first.occurrence(
521-
networks.and.data[["networks"]], networks.and.data[["project.data"]]
522-
)
559+
lapply(AGGREGATION.LEVELS, function(level) {
560+
networks.with.attr = add.vertex.attribute.artifact.first.occurrence(
561+
networks.and.data[["networks"]], networks.and.data[["project.data"]],
562+
aggregation.level = level
563+
)
523564

524-
actual.attributes = lapply(networks.with.attr, igraph::get.vertex.attribute, name = "first.occurrence")
565+
actual.attributes = lapply(networks.with.attr, igraph::get.vertex.attribute, name = "first.occurrence")
525566

526-
expect_equal(expected.attributes, actual.attributes)
567+
expect_equal(expected.attributes[[level]], actual.attributes)
568+
})
527569
})
528570

529571
#' Test the add.vertex.attribute.artifact.change.count method
@@ -533,15 +575,31 @@ test_that("Test add.vertex.attribute.artifact.change.count", {
533575

534576
networks.and.data = get.network.covariates.test.networks("artifact")
535577

536-
expected.attributes = network.covariates.test.build.expected(list(1L), list(1L), list(3L, 1L))
578+
expected.attributes = list(
579+
range = network.covariates.test.build.expected(
580+
list(1L), list(1L), list(3L, 1L)),
581+
cumulative = network.covariates.test.build.expected(
582+
list(1L), list(2L), list(3L, 1L)),
583+
all.ranges = network.covariates.test.build.expected(
584+
list(2L), list(2L), list(3L, 1L)),
585+
project.cumulative = network.covariates.test.build.expected(
586+
list(1L), list(2L), list(3L, 1L)),
587+
project.all.ranges = network.covariates.test.build.expected(
588+
list(2L), list(2L), list(3L, 1L)),
589+
complete = network.covariates.test.build.expected(
590+
list(2L), list(2L), list(3L, 1L))
591+
)
537592

538593
## Test
539594

540-
networks.with.attr = add.vertex.attribute.artifact.change.count(
541-
networks.and.data[["networks"]], networks.and.data[["project.data"]]
542-
)
595+
lapply(AGGREGATION.LEVELS, function(level) {
596+
networks.with.attr = add.vertex.attribute.artifact.change.count(
597+
networks.and.data[["networks"]], networks.and.data[["project.data"]],
598+
aggregation.level = level
599+
)
543600

544-
actual.attributes = lapply(networks.with.attr, igraph::get.vertex.attribute, name = "change.count")
601+
actual.attributes = lapply(networks.with.attr, igraph::get.vertex.attribute, name = "change.count")
545602

546-
expect_identical(expected.attributes, actual.attributes)
603+
expect_equal(expected.attributes[[level]], actual.attributes)
604+
})
547605
})

0 commit comments

Comments
 (0)