Skip to content
Snippets Groups Projects
Commit e6f3f7ab authored by Liuxi Mei's avatar Liuxi Mei
Browse files

update package

parent 450f1392
No related branches found
No related tags found
2 merge requests!2Master,!1presetation
Pipeline #140494 failed
^.*\.Rproj$
^\.Rproj\.user$
Package: exercise
Package: Advanced_R_Group_Cooperation
Type: Package
Title: Lab 3 exercise
Version: 1.0
Date: 2024-09-12
Author:Liuxi Mei
Author: Liuxi Mei
Maintainer: Liuxi Mei <liume102@student.liu.se>
Description: This is a exercise for lab 3.
Description: This is a exercise package for advanced R .
License: GPL (>= 2)
RoxygenNote: 7.3.2
Encoding: UTF-8
Depends:
R (>= 2.10)
LazyData: true
Suggests:
testthat (>= 3.0.0)
Config/testthat/edition: 3
#'
#' @format ## `who`
#' A data frame with 7,240 rows and 60 columns:
#' graph
#' @format A data frame with 18 rows and 3 columns:
#' \describe{
#' \item{country}{Country name}
#' \item{iso2, iso3}{2 & 3 letter ISO country codes}
#' \item{year}{Year}
#' \item{v1}{node name}
#' \item{v2}{node name}
#' \item{w}{the weight between node v1 and node v2}
#' ...
#' }
wiki_graph
\ No newline at end of file
File moved
library(dplyr, warn.conflicts = FALSE)
library(rvest)
library(tidyr)
library(readr)
library(usethis)
wiki_graph <-data.frame(v1=c(1,1,1,2,2,2,3,3,3,3,4,4,4,5,5,6,6,6),
v2=c(2,3,6,1,3,4,1,2,4,6,2,3,5,4,6,1,3,5),
w=c(7,9,14,7,10,15,9,10,11,2,15,11,6,6,9,14,2,9))
write_csv(wiki_graph, "data-raw/wiki_graph.csv")
usethis::use_data(wiki_graph, overwrite = TRUE)
\ No newline at end of file
v1,v2,w
1,2,7
1,3,9
1,6,14
2,1,7
2,3,10
2,4,15
3,1,9
3,2,10
3,4,11
3,6,2
4,2,15
4,3,11
4,5,6
5,4,6
5,6,9
6,1,14
6,3,2
6,5,9
File added
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html
library(testthat)
library(Advanced_R_Group_Cooperation)
test_check("Advanced_R_Group_Cooperation")
# context("dijkstra")
library(testthat)
wiki_graph <-
data.frame(v1=c(1,1,1,2,2,2,3,3,3,3,4,4,4,5,5,6,6,6),
v2=c(2,3,6,1,3,4,1,2,4,6,2,3,5,4,6,1,3,5),
w=c(7,9,14,7,10,15,9,10,11,2,15,11,6,6,9,14,2,9))
test_that("outputs are correct in the Dijkstra algorithm.", {
expect_equal(dijkstra(wiki_graph,1), c(0,7,9,20,20,11))
expect_equal(dijkstra(wiki_graph,3), c(9,10,0,11,11,2))
})
test_that("Error messages are returned for erronous input in the Dijkstra algorithm.", {
wiki_wrong_graph <- wiki_graph
names(wiki_wrong_graph) <- c("v1, v3, w")
expect_error(dijkstra(wiki_wrong_graph, 3))
wiki_wrong_graph <- wiki_graph[1:2]
expect_error(dijkstra(wiki_wrong_graph, 3))
expect_error(dijkstra(wiki_graph, 7))
expect_error(dijkstra(as.matrix(wiki_graph), 3))
})
library(testthat)
test_that("GDC is calculated correctly.", {
expect_equal(euclidean(123612, 13892347912), 4)
expect_equal(euclidean(100, 1000), 100)
expect_equal(euclidean(-100, 1000), 100)
})
test_that("Wrong input throws an error.", {
expect_error(euclidean("100", 1000))
expect_error(euclidean(100, "1000"))
expect_error(euclidean(TRUE, "1000"))
})
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment