diff --git a/internal/search/photos_filter_f_number_test.go b/internal/search/photos_filter_f_number_test.go new file mode 100644 index 000000000..c91c62a2f --- /dev/null +++ b/internal/search/photos_filter_f_number_test.go @@ -0,0 +1,207 @@ +package search + +import ( + "testing" + + "github.com/photoprism/photoprism/internal/form" + "github.com/stretchr/testify/assert" +) + +func TestPhotosFilterFNumber(t *testing.T) { + t.Run("3.2", func(t *testing.T) { + var f form.SearchPhotos + + f.F = "3.2" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, float32(3.2), r.PhotoFNumber) + assert.LessOrEqual(t, float32(3.2), r.PhotoFNumber) + } + assert.Equal(t, len(photos), 1) + }) + t.Run("3.5-5", func(t *testing.T) { + var f form.SearchPhotos + + f.F = "3.5-5" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, float32(5), r.PhotoFNumber) + assert.LessOrEqual(t, float32(3.5), r.PhotoFNumber) + } + + assert.Equal(t, len(photos), 3) + }) + t.Run("3-10", func(t *testing.T) { + var f form.SearchPhotos + + f.F = "3-10" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, float32(10), r.PhotoFNumber) + assert.LessOrEqual(t, float32(3), r.PhotoFNumber) + } + + assert.Equal(t, len(photos), 5) + }) + t.Run("8", func(t *testing.T) { + var f form.SearchPhotos + + f.F = "8" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, len(photos), 0) + }) + t.Run("-100", func(t *testing.T) { + var f form.SearchPhotos + + f.F = "-100" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + assert.GreaterOrEqual(t, len(photos), 40) + }) + t.Run("invalid", func(t *testing.T) { + var f form.SearchPhotos + + f.F = "%gold" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 40) + }) +} + +func TestPhotosQueryFNumber(t *testing.T) { + t.Run("3.2", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "f:\"3.2\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, float32(3.2), r.PhotoFNumber) + assert.LessOrEqual(t, float32(3.2), r.PhotoFNumber) + } + + assert.Equal(t, len(photos), 1) + }) + t.Run("3.5-5", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "f:\"3.5-5\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, float32(5), r.PhotoFNumber) + assert.LessOrEqual(t, float32(3.5), r.PhotoFNumber) + } + assert.Equal(t, len(photos), 3) + }) + t.Run("3-10", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "f:\"3-10\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, float32(10), r.PhotoFNumber) + assert.LessOrEqual(t, float32(3), r.PhotoFNumber) + } + + assert.Equal(t, len(photos), 5) + }) + t.Run("8", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "f:\"8\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("-100", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "f:\"-100\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 40) + }) + t.Run("invalid", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "f:\"%gold\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 40) + + }) +} diff --git a/internal/search/photos_filter_focal_length_test.go b/internal/search/photos_filter_focal_length_test.go new file mode 100644 index 000000000..4e0a14fc7 --- /dev/null +++ b/internal/search/photos_filter_focal_length_test.go @@ -0,0 +1,207 @@ +package search + +import ( + "testing" + + "github.com/photoprism/photoprism/internal/form" + "github.com/stretchr/testify/assert" +) + +func TestPhotosFilterFocalLength(t *testing.T) { + t.Run("28", func(t *testing.T) { + var f form.SearchPhotos + + f.Mm = "28" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, 28, r.PhotoFocalLength) + assert.LessOrEqual(t, 28, r.PhotoFocalLength) + } + assert.Equal(t, len(photos), 1) + }) + t.Run("28-50", func(t *testing.T) { + var f form.SearchPhotos + + f.Mm = "28-50" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, 50, r.PhotoFocalLength) + assert.LessOrEqual(t, 28, r.PhotoFocalLength) + } + + assert.Equal(t, len(photos), 3) + }) + t.Run("1-400", func(t *testing.T) { + var f form.SearchPhotos + + f.Mm = "1-400" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, 400, r.PhotoFocalLength) + assert.LessOrEqual(t, 1, r.PhotoFocalLength) + } + + assert.Equal(t, len(photos), 5) + }) + t.Run("22", func(t *testing.T) { + var f form.SearchPhotos + + f.Mm = "22" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, len(photos), 0) + }) + t.Run("-100", func(t *testing.T) { + var f form.SearchPhotos + + f.Mm = "-100" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + assert.GreaterOrEqual(t, len(photos), 40) + }) + t.Run("invalid", func(t *testing.T) { + var f form.SearchPhotos + + f.Mm = "%gold" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 40) + }) +} + +func TestPhotosQueryFocalLength(t *testing.T) { + t.Run("28", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "mm:\"28\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, 28, r.PhotoFocalLength) + assert.LessOrEqual(t, 28, r.PhotoFocalLength) + } + + assert.Equal(t, len(photos), 1) + }) + t.Run("28-30", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "mm:\"28-30\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, 30, r.PhotoFocalLength) + assert.LessOrEqual(t, 28, r.PhotoFocalLength) + } + + assert.Equal(t, len(photos), 2) + }) + t.Run("1-400", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "mm:\"1-400\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, 400, r.PhotoFocalLength) + assert.LessOrEqual(t, 1, r.PhotoFocalLength) + } + + assert.Equal(t, len(photos), 5) + }) + t.Run("18", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "mm:\"18\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("-100", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "mm:\"-100\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 40) + }) + t.Run("invalid", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "mm:\"%gold\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 40) + }) +} diff --git a/internal/search/photos_filter_iso_test.go b/internal/search/photos_filter_iso_test.go new file mode 100644 index 000000000..fc9e5367d --- /dev/null +++ b/internal/search/photos_filter_iso_test.go @@ -0,0 +1,207 @@ +package search + +import ( + "testing" + + "github.com/photoprism/photoprism/internal/form" + "github.com/stretchr/testify/assert" +) + +func TestPhotosFilterIso(t *testing.T) { + t.Run("200", func(t *testing.T) { + var f form.SearchPhotos + + f.Iso = "200" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, 200, r.PhotoIso) + assert.LessOrEqual(t, 200, r.PhotoIso) + } + assert.Equal(t, len(photos), 1) + }) + t.Run("200-400", func(t *testing.T) { + var f form.SearchPhotos + + f.Iso = "200-400" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, 400, r.PhotoIso) + assert.LessOrEqual(t, 200, r.PhotoIso) + } + + assert.Equal(t, len(photos), 4) + }) + t.Run("1-400", func(t *testing.T) { + var f form.SearchPhotos + + f.Iso = "1-400" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, 400, r.PhotoIso) + assert.LessOrEqual(t, 1, r.PhotoIso) + } + + assert.Equal(t, len(photos), 5) + }) + t.Run("155", func(t *testing.T) { + var f form.SearchPhotos + + f.Iso = "155" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, len(photos), 0) + }) + t.Run("-100", func(t *testing.T) { + var f form.SearchPhotos + + f.Iso = "-100" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + assert.GreaterOrEqual(t, len(photos), 40) + }) + t.Run("invalid", func(t *testing.T) { + var f form.SearchPhotos + + f.Iso = "%gold" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 40) + }) +} + +func TestPhotosQueryIso(t *testing.T) { + t.Run("200", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "iso:\"200\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, 200, r.PhotoIso) + assert.LessOrEqual(t, 200, r.PhotoIso) + } + + assert.Equal(t, len(photos), 1) + }) + t.Run("200-400", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "iso:\"200-400\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, 400, r.PhotoIso) + assert.LessOrEqual(t, 200, r.PhotoIso) + } + + assert.Equal(t, len(photos), 4) + }) + t.Run("1-400", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "iso:\"1-400\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + + for _, r := range photos { + assert.GreaterOrEqual(t, 400, r.PhotoIso) + assert.LessOrEqual(t, 1, r.PhotoIso) + } + + assert.Equal(t, len(photos), 5) + }) + t.Run("155", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "iso:\"155\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.Equal(t, len(photos), 0) + }) + t.Run("-100", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "iso:\"-100\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 40) + }) + t.Run("invalid", func(t *testing.T) { + var f form.SearchPhotos + + f.Query = "iso:\"%gold\"" + f.Merged = true + + photos, _, err := Photos(f) + + if err != nil { + t.Fatal(err) + } + assert.GreaterOrEqual(t, len(photos), 40) + }) +}