Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgirard committed Oct 27, 2024
1 parent cd53d78 commit 17d81ec
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 748 deletions.
14 changes: 4 additions & 10 deletions R/instrument_oop.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ summary.circumplex_instrument <- function(object, scales = TRUE, anchors = TRUE,
items = TRUE, norms = TRUE, ...) {
x <- object
print(x)
if (scales == TRUE) {
if (scales) {
cat("\n")
scales(x)
}
if (anchors == TRUE) {
if (anchors) {
cat("\n")
anchors(x)
}
if (items == TRUE) {
if (items) {
cat("\n")
items(x)
}
if (norms == TRUE) {
if (norms) {
cat("\n")
norms(x)
}
Expand Down Expand Up @@ -167,12 +167,6 @@ norms <- function(x) {
samples <- x$Norms[[2]]
n_norms <- nrow(samples)

if (n_norms == 0) {
cat("The ", x$Details$Abbrev, " currently has no normative data sets.",
"\n", sep = "")
return()
}

cat("The ", x$Details$Abbrev, " currently has ", n_norms,
" normative data set(s):", "\n", sep = "")

Expand Down
27 changes: 27 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ str_percent <- function(x, digits = 2) {

# Determine good max amplitude value for circle plot ---------------------------
pretty_max <- function(v) {

# What is the largest value?
amax <- max(v, na.rm = TRUE)
options <- c(
-5.00, -4.00, -3.00, -2.50, -2.00,
Expand All @@ -56,22 +58,29 @@ pretty_max <- function(v) {
0.50, 0.75, 1.00, 1.25, 1.50,
2.00, 2.50, 3.00, 4.00, 5.00
)
# If negative, decrease scalar (how much buffer space to add)
if (amax < 0 ) {
scalar <- 0.5
} else {
scalar <- 1.5
}
# Which options are good candidates?
match <- options > amax * scalar
# Are there any candidates?
if (sum(match) >= 1) {
# Take the smallest candidate
out <- options[match][[1]]
} else {
# Multiply the max and scalar
out <- amax * scalar
}
out
}

# Determine good min amplitude value for circle plot ---------------------------
pretty_min <- function(v) {

# What is the smallest value?
amin <- min(v, na.rm = TRUE)
options <- c(
-5.00, -4.00, -3.00, -2.50, -2.00,
Expand All @@ -82,21 +91,28 @@ pretty_min <- function(v) {
0.50, 0.75, 1.00, 1.25, 1.50,
2.00, 2.50, 3.00, 4.00, 5.00
)
# If negative, increase scalar (how much buffer space to add)
if (amin < 0) {
scalar <- 1.5
} else {
scalar <- 0.5
}
# Which options are candidates?
match <- options < amin * scalar
# Are there any candidates?
if (sum(match) >= 1) {
# Take the largest candidate
candidates <- options[match]
out <- candidates[length(candidates)]
} else {
# Multiply the min and scalar
out <- amin * scalar
}
out
}


# Rescale numeric vector to specified min and max -------------------------
rescale <- function(x, to = c(0, 1), from = range(x, na.rm = TRUE)) {
min_to <- to[1]
max_to <- to[2]
Expand All @@ -109,10 +125,19 @@ rescale <- function(x, to = c(0, 1), from = range(x, na.rm = TRUE)) {

# Assertions --------------------------------------------------------------

is_count <- function(x) {
all(
is.numeric(x),
ceiling(x) == floor(x),
x >= 0
)
}

is_char <- function(x, n = NULL) {
if (is.null(n)) {
is.character(x)
} else {
stopifnot(is_count(n))
is.character(x) && length(x) == n
}
}
Expand All @@ -125,6 +150,7 @@ is_var <- function(x, n = NULL) {
if (is.null(n)) {
is.character(x) || is.numeric(x)
} else {
stopifnot(is_count(n))
(is.character(x) || is.numeric(x)) && length(x) == n
}
}
Expand All @@ -141,6 +167,7 @@ is_num <- function(x, n = NULL) {
if (is.null(n)) {
is.numeric(x)
} else {
stopifnot(is_count(n))
is.numeric(x) && length(x) == n
}
}
Expand Down
99 changes: 99 additions & 0 deletions tests/testthat/_snaps/instrument_oop.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,105 @@
64 items, 8 scales, 1 normative data sets
Hopwood et al. (2011)
<https://doi.org/10.1111/j.1467-6494.2011.00696.x>

The ISC contains 8 circumplex scales.
PA: Sensitive to Control (90 degrees)
BC: Sensitive to Antagonism (135 degrees)
DE: Sensitive to Remoteness (180 degrees)
FG: Sensitive to Timidity (225 degrees)
HI: Sensitive to Passivity (270 degrees)
JK: Sensitive to Dependence (315 degrees)
LM: Sensitive to Affection (360 degrees)
NO: Sensitive to Attention-Seeking (45 degrees)

The ISC is rated using the following 8-point scale.
1. Not at all, never bothers me
2. Very little, rarely bothers me
3. A little, occasionally bothers me
4. Slightly, bothers me less than half the time
5. Somewhat, bothers me more than half of the time
6. Quite, bothers me frequently
7. Very much, bothers me most of the time
8. Extremely, always bothers me

The ISC contains 64 items (open-access):
Prefix: It bothers me when a person...
1. Thinks they are my boss
2. Disregards my feelings
3. Doesn't show any feelings
4. Won't engage in conversation
5. Cannot assert themselves
6. Avoids conflict at all costs
7. Wants to spend lots of time with me
8. Doesn't respect my privacy
9. Orders me around
10. Doesn't respond to me
11. Doesn't want to be friends
12. Is aloof
13. Doesn't have a backbone
14. Always needs support
15. Tries to get close to me really fast
16. Talks themselves up
17. Talks down to me
18. Is hostile
19. Walls themselves off from me
20. Acts like a wallflower
21. Is weak
22. Always seems to need my help
23. Tells me they love me
24. Shows off
25. Will do anything to get what they want
26. Is deceitful
27. Won't share their feelings with me
28. Won't step up to the plate
29. Allows themselves to be dominated by others
30. Acts helpless
31. Expresses concern about me
32. Talks about themselves
33. Has to call the shots
34. Mistrusts me
35. Is unresponsive
36. Doesn't share their ideas
37. Is always submissive
38. Laughs at all my jokes
39. Acts like we're friends when we don't even know each other
40. Has to be right
41. Intimidates me
42. Doesn't care about my feelings
43. Avoids me
44. Won't participate
45. Cannot make decisions
46. Is dependent on me
47. Humors me
48. Interrupts
49. Is bossy
50. Expects the worst out of me
51. Never gets in touch with me
52. Is really shy
53. Is very passive
54. Believes everything I say
55. Believes I can do no wrong
56. Tries to show me how to do things
57. Always puts themselves first
58. Is mean-spirited
59. Pulls away from me
60. Refuses to lead
61. Is easily controlled
62. Is soft
63. Is clingy
64. Takes control

The ISC currently has 1 normative data set(s):
1. 649 American college students
Hopwood et al. (2011)
<https://doi.org/10.1111/j.1467-6494.2011.00696.x>

---

ISC: Interpersonal Sensitivities Circumplex
64 items, 8 scales, 1 normative data sets
Hopwood et al. (2011)
<https://doi.org/10.1111/j.1467-6494.2011.00696.x>

---

Expand Down
Loading

0 comments on commit 17d81ec

Please sign in to comment.