This repository has been archived by the owner on May 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy patharticle_test.go
102 lines (87 loc) · 3.05 KB
/
article_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package goscholar
import (
"errors"
"fmt"
"testing"
)
var article *Article
func init() {
article = &Article{
Title: &Title{
Name: "Deep learning via Hessian-free optimization",
Url: "http://machinelearning.wustl.edu/mlpapers/paper_files/icml2010_Martens10.pdf"},
Year: "2010",
ClusterId: "15502119379559163003",
NumCite: "260",
NumVer: "9",
InfoId: "e6RSJHGXItcJ",
Link: &Link{
Name: "wustl.edu",
Url: "http://machinelearning.wustl.edu/mlpapers/paper_files/icml2010_Martens10.pdf",
Format: "PDF",
},
BibTeX: "@inproceedings{martens2010deep, title={Deep learning via Hessian-free optimization}, author={Martens, James}, booktitle={Proceedings of the 27th International Conference on Machine Learning (ICML-10)}, pages={735--742}, year={2010}}",
Author: []string{"Martens, James"},
Journal: "",
Booktitle: "Proceedings of the 27th International Conference on Machine Learning (ICML-10)",
Volume: "",
Number: "",
Pages: "735--742",
Publisher: "",
}
}
func TestNewArticle(t *testing.T) {
a := newArticle()
title := a.Title
year := a.Year
clusterId := a.ClusterId
numCite := a.NumCite
numVer := a.NumVer
infoId := a.InfoId
link := a.Link
var err error
checkBlank := func(s string) error {
if err != nil {
return err
}
if s != "" {
err = errors.New(fmt.Sprintf("%v is not blank", s))
}
return err
}
checkBlank(title.Name)
checkBlank(title.Url)
checkBlank(year)
checkBlank(clusterId)
checkBlank(numCite)
checkBlank(numVer)
checkBlank(infoId)
checkBlank(link.Name)
checkBlank(link.Url)
checkBlank(link.Format)
if err != nil {
t.Error(err)
}
}
func ExampleString() {
fmt.Println(article)
}
func ExampleJson() {
fmt.Println(article.Json())
// Output:
// {"title":{"name":"Deep learning via Hessian-free optimization","url":"http://machinelearning.wustl.edu/mlpapers/paper_files/icml2010_Martens10.pdf"},"year":"2010","cluster_id":"15502119379559163003","num_cite":"260","num_ver":"9","info_id":"e6RSJHGXItcJ","link":{"name":"wustl.edu","url":"http://machinelearning.wustl.edu/mlpapers/paper_files/icml2010_Martens10.pdf","format":"PDF"},"bibtex":"@inproceedings{martens2010deep, title={Deep learning via Hessian-free optimization}, author={Martens, James}, booktitle={Proceedings of the 27th International Conference on Machine Learning (ICML-10)}, pages={735--742}, year={2010}}","author":["Martens, James"],"journal":"","booktitle":"Proceedings of the 27th International Conference on Machine Learning (ICML-10)","volume":"","number":"","pages":"735--742","publisher":""}
}
func TestIsValid(t *testing.T) {
// test case 1
aInvalid := newArticle()
aInvalid.Title.Name = "User profiles for author:\"y bengio\""
aInvalid.Title.Url = "/citations?view_op=search_authors&mauthors=author:%22y+bengio%22&hl=en&oi=ao"
if aInvalid.isValid() {
t.Error(fmt.Sprintf("\n%v \nThis title should be invalid", aInvalid.Title.Name))
}
aInvalid = newArticle()
aInvalid.Year = "1206"
if aInvalid.isValid() {
t.Error(fmt.Sprintf("\n%v \nThis year should be invalid", aInvalid.Year))
}
}