built_in_test.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2020 gorse Project Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package model
  15. import (
  16. "github.com/stretchr/testify/assert"
  17. "os"
  18. "path/filepath"
  19. "testing"
  20. )
  21. func TestUnzip(t *testing.T) {
  22. // Download
  23. zipName, err := downloadFromUrl("https://cdn.gorse.io/datasets/yelp.zip", os.TempDir())
  24. assert.Nil(t, err, "download file failed ")
  25. // Extract files
  26. fileNames, err := unzip(zipName, DataSetDir)
  27. // Check
  28. assert.Nil(t, err, "unzip file failed ")
  29. assert.Equal(t, 2, len(fileNames), "Number of file doesn't match")
  30. }
  31. func TestLocateBuiltInDataset(t *testing.T) {
  32. trainFilePath, testFilePath, err := LocateBuiltInDataset("ml-1m", FormatNCF)
  33. assert.NoError(t, err)
  34. assert.Equal(t, filepath.Join(DataSetDir, "ml-1m", "train.txt"), trainFilePath)
  35. assert.Equal(t, filepath.Join(DataSetDir, "ml-1m", "test.txt"), testFilePath)
  36. }